我是maven的新手,在通过maven运行类文件时遇到问题
运行良好 mvn exec:java -Dexec.mainClass =“com.test.Test”
但不是与 mvn exec:exec -Dexec.executable = java -Dexec.mainClass =“com.test.Test”
它要求java参数
F:\data\work\Test>mvn exec:exec -Dexec.executable=java -Dexec.mainClass="com.test.Test"
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)
where options include:
-d32 use a 32-bit data model if available
-d64 use a 64-bit data model if available
-server to select the "server" VM
-hotspot is a synonym for the "server" VM [deprecated]
The default VM is server.
-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
我已经提供了一个类文件然后为什么它不能选择它? 我试着通过pom提供这些。
我正在使用exec:exec,因为我不想从 MAVEN_OPTS
传递VM参数这是我的pom
<profiles>
<profile>
<id>fib</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<mainClass>com.test.Test</mainClass>
<executable>java</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
我错过了什么?
所以出现2个问题 -
1)尽管传递了mainClass,但是我要求我传递java参数是什么?
2)如何使用exec-maven-plugin传递VM参数?
我发现这是第二个问题 using maven 'exec:exec' with arguments
答案 0 :(得分:4)
mvn exec:exec -Dexec.executable=java -Dexec.args="-classpath target/classes -XX:+PrintGCDetails com.test.Test"
如果您担心依赖于classpath然后make a fat jar并在classpath中设置
有趣的讨论:http://chat.stackoverflow.com/rooms/67085/discussion-between-biker-and-jigar-joshi