我有一个在localhost:9080上运行的Java应用程序,以及在同一项目的WebContent文件夹内的另一个angular5项目(angularWeb),该项目在不同的端口localhost:4200上运行
根据要求,我需要集成两个项目以在localhost:9080上的同一服务器上运行,并且两个项目(java和angular项目)都必须位于同一位置,这就是为什么我在web内容文件夹中有angular项目的原因。
请帮助我了解缺少的内容。
首先:我在angular项目中创建了一个proxy.conf.json文件,以localhost:9080为目标。
第二:我已经更改了package.json以通过代理文件启动角度应用程序,如下所示: “ start”:“ ng serve --proxy-conf proxy.conf.json”,
第三:我在build.xml文件中添加了一些目标
...
...
<property name="project.angularWebPath" location="${project.webContentPathh}/angularweb" />
<target name="mkfolders">
<mkdir dir="${project.webContentPath}/js" />
<mkdir dir="${project.webContentPath}/css" />
<mkdir dir="${project.webContentPath}/img" />
<mkdir dir="${project.webContentPath}/lib" />
<mkdir dir="${project.webContentPath}/partials" />
</target>
<target name="mkfiles">
<touch file="${project.webContentPath}/js/app.js" />
<touch file="${project.webContentPath}/js/controller.js" />
<touch file="${project.webContentPath}/js/directives.js" />
<touch file="${project.webContentPath}/js/filters.js" />
<touch file="${project.webContentPath}/js/services.js" />
<touch file="${project.webContentPath}/index.html" />
</target>
<target name="ngBuild">
<echo>Building Angular Project</echo>
<exec executable="${project.angularWebPath}/node_modules/@angular/cli/bin/ng.cmd" failonerror="true">
<arg value="build" />
<arg value="--prod" />
<arg value="--bh" />
</exec>
<echo>Built Angular Project</echo>
</target>
<target name="angularBuild">
<antcall target="mkfolders" />
<antcall target="mkfiles" />
<!--<antcall target="npmInstall" />-->
<antcall target="ngBuild" />
</target>
...
...
现在,当我在ANT中运行angularBuild时,会出现以下错误
Buildfile: D:\devops\repository\komponente_server\RechercheEAR\build.xml
[clover-env] Loading clover.xml: jar:file:/D:/devops/repository/komponente_server/Shared/testlib/clover.jar!/clover.xml
angularBuild:
[clover-env] Loading clover.xml: jar:file:/D:/devops/repository/komponente_server/Shared/testlib/clover.jar!/clover.xml
mkfolders:
[clover-env] Loading clover.xml: jar:file:/D:/devops/repository/komponente_server/Shared/testlib/clover.jar!/clover.xml
mkfiles:
[clover-env] Loading clover.xml: jar:file:/D:/devops/repository/komponente_server/Shared/testlib/clover.jar!/clover.xml
ngBuild:
[echo] Building Angular Project
BUILD FAILED
D:\devops\repository\komponente_server\RechercheEAR\build.xml:71: The following error occurred while executing this line:
D:\devops\repository\komponente_server\RechercheEAR\build.xml:60: Execute failed: java.io.IOException: Cannot run program "D:\devops\repository\komponente_server\Recherche\WebContent\angularweb\node_modules\@angular\cli\bin\ng.cmd" (in directory "D:\devops\repository\komponente_server"): CreateProcess error=2, The system cannot find the file specified
Total time: 6 seconds
答案 0 :(得分:0)
Ant的exec
任务在直接在Windows中启动文件时遇到问题。尝试将executable
属性设置为仅cmd
本身,并将文件作为参数传递。官方文档页面详细介绍了这种情况:https://ant.apache.org/manual/Tasks/exec.html
此外,通常最好通过目标依赖关系来构建构建,而不是使用antcall
任务的顺序列表。
<property name="project.angularWebPath" location="${project.webContentPathh}/angularweb" />
<target name="mkfolders">
<mkdir dir="${project.webContentPath}/js" />
<mkdir dir="${project.webContentPath}/css" />
<mkdir dir="${project.webContentPath}/img" />
<mkdir dir="${project.webContentPath}/lib" />
<mkdir dir="${project.webContentPath}/partials" />
</target>
<target name="mkfiles" depends="mkfolders">
<touch file="${project.webContentPath}/js/app.js" />
<touch file="${project.webContentPath}/js/controller.js" />
<touch file="${project.webContentPath}/js/directives.js" />
<touch file="${project.webContentPath}/js/filters.js" />
<touch file="${project.webContentPath}/js/services.js" />
<touch file="${project.webContentPath}/index.html" />
</target>
<target name="ngBuild" depends="mkfiles,mkfolders">
<echo message="Building Angular Project" />
<exec executable="cmd" failonerror="true">
<arg value="/C" />
<arg value="${project.angularWebPath}/node_modules/@angular/cli/bin/ng.cmd" />
<arg value="build" />
<arg value="--prod" />
<arg value="--bh" />
</exec>
<echo message="Built Angular Project" />
</target>
<target name="angularBuild" depends="mkfiles,mkfolders,ngBuild" />