Ant build executes cordova

徘徊边缘 提交于 2019-12-12 16:06:05

问题


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: 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)

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.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


回答1:


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>

If that still doesn't work, give the full path for cordova. An environment variable should work if you have one defined.



来源:https://stackoverflow.com/questions/19157965/ant-build-executes-cordova

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!