通过"mvn exec:exec"运行一个类文件

6

我是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.xml中提供这些依赖。

我正在使用exec: exec,因为我不想从MAVEN_OPTS传递VM参数。

这是我的pom.xml文件:

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

我错过了什么?

所以有两个问题:
1)我错过了什么,尽管我传递了mainClass,但它要求我传递java参数?
2)如何使用exec-maven-plugin传递VM参数?

我已经在这里找到了关于第二个问题的答案: 使用maven 'exec:exec'传递参数


尝试运行以下命令:mvn exec:java -DmainClass="com.text.Test" - jmj
@JigarJoshi 它可以通过 mvn exec:java -Dexec.mainClass="com.test.Test" 运行,但我想使用VM参数而不是MAVEN_OPTS。 - Ravi Sahu
@JigarJoshi 这里有两个问题<br>1)我该如何传递参数给Java?因为它要求我传递Java参数?<br>2)我该如何传递参数? - Ravi Sahu
你是指传递给main函数的命令行参数还是传递给JVM本身的参数?关于JVM,请参考我上面的评论。 - jmj
请查看[http://mojo.codehaus.org/exec-maven-plugin/]。这就是为什么我使用exec:exec,它可以在单独的进程中执行程序和Java程序。 - Ravi Sahu
显示剩余14条评论
1个回答

7

1
谢谢,这次讨论真的很有帮助。 - Ravi Sahu
很高兴能帮到你,随意将其标记为已接受的答案 @Biker - jmj

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接