Ant build 执行cordova [英] Ant build executes cordova
问题描述
我为我的cordova项目创建了一个ant build,如下所示:
I created an ant build for my cordova project as following:
<project default="build">
<target name="init-android">
<exec executable="cordova">
<arg value="platform"/>
<arg value="add"/>
<arg value="android"/>
</exec>
<exec executable="cordova">
<arg value="build"/>
</exec>
</target>
</project>
但是我收到了这个错误:
But I got this error:
C:\path_to_project\build.xml:3: 执行失败: java.io.IOException:无法运行程序cordova":CreateProcess error=2,系统无法运行找到指定的文件在 java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)在 java.lang.Runtime.exec(Runtime.java:615)在 org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Java13CommandLauncher.java:41)
C:\path_to_project\build.xml:3: Execute failed: java.io.IOException: Cannot run program "cordova": CreateProcess error=2, The system cannot find the file specified at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029) at java.lang.Runtime.exec(Runtime.java:615) at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav a13CommandLauncher.java:41)
我可以在命令提示符下毫无问题地运行cordova命令,我有:
I can run cordova command with no problem from the command prompt, I have:
JAVA_HOME = C:/Program Files/Java/jdk1.7.0_10/ANT_HOME = C:\Program Files\Java\apache-ant-1.9.2NODEJS_HOME = C:\Program Files\nodejs
JAVA_HOME = C:/Program Files/Java/jdk1.7.0_10/ ANT_HOME = C:\Program Files\Java\apache-ant-1.9.2 NODEJS_HOME = C:\Program Files\nodejs
他们都在我的路上.我不明白为什么它不起作用.请帮忙.谢谢
and they are all in my path. I don't understand why it doesn't work. Please help. Thanks
推荐答案
通常在使用 Java 应用程序在 Windows 中启动程序时,我经常需要执行 cmd.exe
并将其完整传递我实际想要运行的程序的路径.这允许以您期望的方式设置系统环境变量等.试试这个:
Generally when working with a Java application to launch programs in Windows, I often have to execute cmd.exe
and pass it the full path to the program I actually want to run. This allows system environment variables and such to be set up the way you expect. Try this:
<project default="build">
<target name="init-android">
<exec executable="cmd.exe">
<arg value="/C"/>
<arg value="cordova"/>
<arg value="platform"/>
<arg value="add"/>
<arg value="android"/>
</exec>
<exec executable="cmd.exe">
<arg value="/C"/>
<arg value="cordova"/>
<arg value="build"/>
</exec>
</target>
</project>
如果还是不行,请给出cordova的完整路径.如果您定义了环境变量,则应该可以使用.
If that still doesn't work, give the full path for cordova. An environment variable should work if you have one defined.
这篇关于Ant build 执行cordova的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!