【问题标题】:Running a class file through "mvn exec:exec"通过“mvn exec:exec”运行类文件
【发布时间】:2015-02-15 14:03:02
【问题描述】:

我是 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

【问题讨论】:

  • 试试mvn exec:java -DmainClass="com.text.Test"
  • @JigarJoshi 它使用 mvn exec:java -Dexec.mainClass="com.test.Test" 运行,但我想要 VM 参数而不是 MAVEN_OPTS
  • 你可以通过-Dexec.args="-X_____"传递VM参数
  • @JigarJoshi 这里有 2 个问题 1) 我如何将参数传递给 java,看到它要求我传递 java 参数?**
    **2) 我如何传递论据?
  • 你的意思是 main 的命令行参数或 JVM 本身的参数,对于 JVM,请参阅我上面的评论

标签: java maven exec-maven-plugin


【解决方案1】:
mvn exec:exec -Dexec.executable=java -Dexec.args="-classpath target/classes -XX:+PrintGCDetails com.test.Test"

如果您担心依赖项在类路径中,那么 make a fat jar 并将其设置在类路径中

有趣的讨论:https://chat.stackoverflow.com/rooms/67085/discussion-between-biker-and-jigar-joshi

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-11
  • 2019-04-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-09
相关资源
最近更新 更多