Sti*_*ens 5 maven-2 exec-maven-plugin
在我的pom中,我添加了exec-maven-plugin来调用一个生成文件的java类.此类需要将一些参数传递给main方法,其中一个是输入文件的位置(在项目外部).到目前为止,我一直在使用相对路径,这工作正常:
<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>
Run Code Online (Sandbox Code Playgroud)
现在我开始使用hudson来安装/打包和部署战争,我不能再使用这个相对路径了.简单我想,我只是在调用maven时传递输入文件的位置:
mvn clean package -Dlangdir = C:/ somedir
然后改变pom像:
<argument>${langdir}/PMLanguage.xls</argument>
Run Code Online (Sandbox Code Playgroud)
但是,此参数在此处仅被忽略.主类作为参数接收的路径变为null/PMLanguage.xls.参数本身在maven中可用,我使用antrun插件中的echo测试成功.正确的道路得到了回应.
你传递给maven的参数是否默认无论你在pom中引用它们在哪里都没有?
感谢任何帮助,
Stijn
Pas*_*ent 13
我无法重现这个问题.我使用了以下测试类:
package com.stackoverflow.q3421918;
public class Hello
{
public static void main( String[] args )
{
System.out.println( args[0] + " " + args[1] );
}
}
Run Code Online (Sandbox Code Playgroud)
以下是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>
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出:
$ 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测试.
| 归档时间: |
|
| 查看次数: |
19349 次 |
| 最近记录: |