我正在使用Apache Ant进行构建。我有一些作者脚本属于vendor / bin文件夹中的几个供应商。我已将此文件夹添加到系统路径中,如果我在命令窗口中运行命令,但在构建文件中,我收到错误。 有什么我应该做的不同吗?以前是一个例子:
<?xml version="1.0" encoding="UTF-8"?>
<project name="MyProject" default="build" basedir=".">
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="phpcpd">
<arg value="--version" />
</exec>
</target>
</project>'
我在运行ant phpcpd
phpcpd:
BUILD FAILED
C:\xxxxxx\xxxxxxx\build.xml:96: Execute failed: java.io.IO Exce
ption: Cannot run program "phpcpd": CreateProcess error=2, The system
cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1041)
at java.lang.Runtime.exec(Runtime.java:617)
at org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher.exec(Jav
a13CommandLauncher.java:41)
at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:428)
at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:442)
at org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:628)
at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:669)
at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:495)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
...
但phpcpd --version
适用于命令提示符
答案 0 :(得分:0)
ANT不知道 phpcpd 在哪里,因为它不与您的Command Promt共享路径。
一种方法是创建一个.bat文件来运行 phpcpd
使用以下内容创建phpcpd.bat:
@echo off
phpcpd --version
您的构建脚本将从以下位置更新:
<exec executable="phpcpd">
<arg value="--version" />
</exec>
收件人:<exec executable="phpcpd.bat"/>
以上假设使用Windows Command Promt
答案 1 :(得分:0)
我的解决方案是使用脚本的.phar文件。这样,构建文件在很大程度上变得与平台无关。所以
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="phpcpd">
<arg value="--version" />
</exec>
</target>
变成了:
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<exec executable="php">
<arg value="${phpcpd}" />
<arg value="--version" />
</exec>
</target>
其中${phpcpd}
是phar文件的路径
答案 2 :(得分:0)
我正在使用绝对路径和可配置的executable.properties,如下所示:
的build.xml
<project name="build">
<property file="executable.properties" />
<target name="run-phpcd" unless="${phpcpd.skip}">
<exec executable="${phpcpd.executable}"><!-- .. --></exec>
</target>
</project>
executable.dist.properties
phpcpd.skip = no
#phpcpd.executable = C:\path\to\phpcpd.bat
phpcpd.executable = /path/to/phpcpd.sh
这两个文件都可以提交到您的VCS,用于复制模板文件(* .dist.properties)并将其重命名为executable.properties。将此文件添加到VCS的忽略列表中。