在Maven编译时需要执行Java程序,Java程序的参数如何写呢? 特别是类路径参数如何写呢?下面这个写法会报"Unrecognized option -cp ..."异常:
<argument>-cp ${basedir}/../xx/lib/xxx.jar</argument>
正确的写法是将上面的类路径参数分成2个参数,就OK了:
<argument>-cp</argument>
<argument>${basedir}/../xx/lib/xxx.jar</argument>
完整的例子:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>run-test</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Xms128m</argument>
<argument>-Xmx512m</argument>
<argument>-cp</argument>
<argument>${basedir}/../xx/lib/xxx.jar</argument>
<argument>-jar</argument>
<!-- Copy allatori.jar to 'allatori' directory to use the commented line -->
<argument>${basedir}/../allatori/lib/allatori.jar</argument>
<!-- <argument>${basedir}/xx/xx.jar</argument> -->
<argument>${basedir}/target/xx.xml</argument>
</arguments>
</configuration>
</plugin>