如何使用 exec-maven-plugin 设置 VM 参数和程序参数? [英] How to set both VM Params and Program args using exec-maven-plugin?

查看:238
本文介绍了如何使用 exec-maven-plugin 设置 VM 参数和程序参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 exec-maven-plugin 来运行 java 应用程序.我需要传递 JVM 参数和程序参数.我正在像这样设置 JVM 参数:

I am using exec-maven-plugin to run java app. I need to pass both JVM params and program arguments. I am setting JVM params like this:

<artifactId>exec-maven-plugin</artifactId>
       <version>1.6.0</version>
           <executions>
               <execution>
                   <id>MyId</id>
                   <goals>
                       <goal>java</goal>
                   </goals>
                   <configuration>
                       <mainClass>MyClass</mainClass>
                       <arguments>
                           <argument>-XX:+UseG1GC</argument>
                           <argument>-Xms2G</argument>
                           <argument>-Xmx2G</argument>                                    
                       </arguments>
                   </configuration>
               </execution>

...

并运行程序:

mvn exec:java@MyId  -Dexec.args="my params"

但是看起来 pom.xml 中设置的参数没有被 -Dexec.args 使用和覆盖,并且 section 仅用作程序参数.

However it looks like arguments set in pom.xml are not used and overwritten by -Dexec.args, and section is used only as program arguments.

尝试添加到参数中(如 这篇文章),但遇到了

Tried to add into arguments (as shown in this article), but ran into

Unable to parse configuration of mojo org.codehaus.mojo:exec-maven-plugin:1.6.0:java for parameter arguments: Cannot store value into array:
ArrayStoreException -> [Help 1]

在 jboss.org 上发现了类似的未解决问题.

Found similar unresolved problem on jboss.org.

有什么建议吗?

推荐答案

插件页面 - 在它的最后.

Found the answer for my question on the plugin page - at the very end of it.

此目标可帮助您在与 Maven 相同的 VM 中运行 Java 程序.

This goal helps you run a Java program within the same VM as Maven.

目标很长,试图模仿虚拟机的工作方式,但有一些细微的差别.今天所有的差异来自目标处理线程管理的方式.

The goal goes to great length to try to mimic the way the VM works, but there are some small subtle differences. Today all differences come from the way the goal deals with thread management.

注意:java 目标不会产生新进程.任何特定于虚拟机的您要传递给执行的类的选项必须传递给使用 MAVEN_OPTS 环境变量的 Maven VM.

Note: The java goal doesn't spawn a new process. Any VM specific option that you want to pass to the executed class must be passed to the Maven VM using the MAVEN_OPTS environment variable.

这对我不起作用,所以切换到 mvn exec:exec 模式.适用于那里的 JVM 参数.

That doesn't work for me, so switching to mvn exec:exec mode. works for JVM params there.

在这里找到解决方案:使用 Maven 'exec:exec' 和参数

这篇关于如何使用 exec-maven-plugin 设置 VM 参数和程序参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆