java - 通过 "mvn exec:exec"运行class文件

标签 java maven exec-maven-plugin

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

关于java - 通过 "mvn exec:exec"运行class文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27518544/

相关文章:

java - 如何获得与Artifactory Gradle存储库匹配的Gradle版本

java - Sinch 调用按钮错误?

java - Tomcat: "Offending class: javax/servlet/Servlet.class"然后超时

java - Maven - 添加可在 Java 内部访问的校验和

java - maven-exec-plugin 无缘无故抛出异常

java - JTabel 单个单元格文本对齐

java - 删除重复字符,保留顺序

未正确传递 java 编译器注释处理器选项

java - 运行 mvn exec :java on Windows 时出现 ClassNotFoundException

java - 在多模块 Maven 项目中运行 exec-maven-plugin 时出现问题