传递命令行参数在mvn exec:exec

问题描述:

我很惊讶,本应该是一件非常简单的工作,对我来说变成一项非常烦人的任务。我所需要的只是将少量命令行参数传递给我的maven exec:exec插件。不幸的是,使用Google的时间一点都没有帮助。传递命令行参数在mvn exec:exec

这里是我的插件

  <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.2</version> 
      <dependencies> 
       <dependency> 
        <groupId>org.springframework</groupId> 
        <artifactId>spring-instrument</artifactId> 
        <version>${spring.version}</version> 
       </dependency> 
      </dependencies> 
      <configuration> 
       <executable>java</executable> 
       <arguments> 
        <argument>-classpath</argument> 
        <classpath /> 
        <argument>-javaagent:${settings.localRepository}/org/springframework/spring-instrument/${spring.version}/spring-instrument-${spring.version}.jar</argument> 
        <argument>-Xmx256m</argument> 
        <argument>com.myPackage.Myclass</argument> 
       </arguments> 
      </configuration> 
      <executions> 
       <execution> 
        <goals> 
         <goal>exec</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 

现在从命令提示符我在

mvn exec:exec -Dexec.args=-Dmy.property=myProperty 

打字我也试过

mvn exec:exec -Dexec.arguments=-Dmy.property=myProperty 

和许多其他的事情。然而,似乎没有任何工作。我知道exec:exec运行在一个单独的虚拟机中,但根据文档-Dexec.args应该适用于我。有人可以请建议我去哪里错了?

我能得到JVM args作为高管的工作:使用以下EXEC阅读this article后:

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <executions> 
      <execution> 
       <goals> 
        <goal>java</goal> 
       </goals> 
      </execution> 
     </executions> 
     <configuration> 
      <executable>java</executable> 
      <arguments> 
       <argument>-Dhttp.proxyHost=myproxy.example.com</argument> 
       <argument>-Dhttp.proxyPort=8080</argument> 
       <argument>-classpath</argument> 
       <classpath /> 
       <argument>com.example.Main</argument> 
      </arguments> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 

如果要将命令行参数传递给Java VM,请使用<commandlineArgs>标记而不是<arguments>Maven Exec Plugin

干杯

+2

AFAIK这是不正确的。 ''覆盖''列表中设置的任何内容;他们服务于相同的目的。 – smallsense 2013-02-09 11:04:08

我用下面的命令行设置为arguements传递给我的Main-使用exceution插件的类。

mvn clean install -Dexec.arguments="arg0" 
+0

使用目标时不工作exec:exec – 2015-08-07 17:42:31

两种方式来传递命令行参数到MVN:EXEC:

方法1,在命令行上:

mvn exec:java -Dexec.mainClass="com.myPackage.myClass" -Dexec.args="command line arguments" 

方法2,在行家POM文件:

<build> 
    <plugins> 
    <plugin> 
     <groupId>org.codehaus.mojo</groupId> 
     <artifactId>exec-maven-plugin</artifactId> 
     <configuration> 
     <mainClass>com.myPackage.myClass</mainClass> 
     <commandlineArgs>command line arguments</commandlineArgs> 
     </configuration> 
    </plugin> 
    </plugins> 
</build> 

然后在命令行上所有你需要做的就是运行:

mvn exec:java 

祝你好运。

+0

最后以工作命令行方式为例。问题是这个插件的官方文档指定了['commandlineArgs'](http://www.mojohaus.org/exec-maven-plugin/java-mojo.html#commandlineArgs)属性,而事实是它是**代替'args' **。 – uvsmtid 2016-10-17 02:04:10

为什么不使用系统属性?

  <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>exec-maven-plugin</artifactId> 
       <version>1.3.2</version> 
       <executions> 
        <execution> 
         <goals> 
          <goal>java</goal> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <mainClass>bobo.Abc</mainClass> 
        <arguments> 
         <argument>argument1</argument> 
        </arguments> 
        <systemProperties> 
         <systemProperty> 
          <key>jvmProperty1</key> 
          <value>dev</value> 
         </systemProperty> 
        </systemProperties> 
       </configuration> 
      </plugin>