<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.laco.projectmaster.util.LanguageGenerator</mainClass>
<arguments>
<argument>../PM-Config/dev/PMLanguage.xls</argument>
<argument>PM4.0</argument>
<argument>${project.build.outputDirectory}/com/laco/projectmaster/props/resources</argument>
<argument>ProjectMaster</argument>
<argument>Created during maven build (POM Version: ${pom.version})</argument>
</arguments>
</configuration>
</plugin>
现在我开始使用hudson来安装/打包和部署战争,我不能再使用这个相对路径了。简单的我想,我只是在调用maven时传递输入文件的位置:
mvn clean package -Dlangdir = C:/ somedir
然后改变pom:
<argument>${langdir}/PMLanguage.xls</argument>
但是,此参数在此处仅被忽略。主类作为参数接收的路径变为 null / PMLanguage.xls 。参数本身在maven中可用,我使用antrun插件中的echo测试成功。正确的道路得到了回应。
你传递给maven的参数是否默认无论你在pom中引用它们的位置都不可用?
感谢您的帮助,
斯泰恩
答案 0 :(得分:13)
我无法重现这个问题。我使用了以下测试类:
package com.stackoverflow.q3421918;
public class Hello
{
public static void main( String[] args )
{
System.out.println( args[0] + " " + args[1] );
}
}
以下是pom.xml:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow.q3421918</groupId>
<artifactId>Q3421918</artifactId>
<version>1.0-SNAPSHOT</version>
<!-- this was a test for a workaround -->
<properties>
<myprop>${langdir}</myprop>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.stackoverflow.q3421918.Hello</mainClass>
<arguments>
<argument>${myprop}</argument>
<argument>${langdir}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
这是我得到的输出:
$ mvn clean package -Dlangdir=C:/somedir [INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building Q3421918 [INFO] task-segment: [clean, package] [INFO] ------------------------------------------------------------------------ ... [INFO] Preparing exec:java [WARNING] Removing: java from forked lifecycle, to prevent recursive invocation. [INFO] No goals needed for project - skipping [INFO] [exec:java {execution: default}] Hello c:/somedir c:/somedir [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ ...
使用Maven 2.2.1进行测试。