如何使用pom.xml插件添加VM args

Rah*_*rma 5 java vmargs pom.xml maven

我尝试了以下方法,但没有任何工作...我试图从服务器远程访问jmx.

         <jvmArgs>
         <jvmArg>-Dcom.sun.management.jmxremote.port=9999</jvmArg>
        <jvmArg>-Dcom.sun.management.jmxremote.authenticate=false</jvmArg>
          <jvmArg>-Dcom.sun.management.jmxremote.ssl=false</jvmArg>
        </jvmArgs>

        <!-- <systemPropertyVariables> 
                                   <com.sun.management.jmxremote.port>9999</com.sun.management.jmxremote.port> 
                       <com.sun.management.jmxremote.authenticate>false</com.sun.management.jmxremote.a uthenticate> 
                     <com.sun.management.jmxremote.ssl>false</com.sun.management.jmxremote.ssl> 
                 </systemPropertyVariables> -->

                 <!-- <jvmArguments> 
                 <jvmArgument>- Dcom.sun.management.jmxremote.port=9999</jvmArgument> 
                 <jvmArgument>- Dcom.sun.management.jmxremote.authenticate=false</jvmArgument> 
                 <jvmArgument>- Dcom.sun.management.jmxremote.ssl=false</jvmArgument> 
                </jvmArguments> -->
Run Code Online (Sandbox Code Playgroud)

我也试过了

 <options>
            <option>-Dcom.sun.management.jmxremote.port=9999</option> 
            <option>-Dcom.sun.management.jmxremote.authenticate=false</option> 
            <option>-Dcom.sun.management.jmxremote.ssl=false</option> 
            </options>
Run Code Online (Sandbox Code Playgroud)

RIT*_*AVI 16

您可以在不同的点和级别(全局或通过插件配置)为Maven设置Java选项:

插件配置:只是编译
使用Maven的编译器插件配置编译应用程序代码和测试代码,你可以设置所需要的XMX,X毫秒,通过compileArgs配置条目XSS选项,同时适用于编译testCompile目标.这里有一个官方的例子,也有像这样的其他SO答案.一个例子也如下所示.

插件配置:仅用于测试执行
使用Maven Surefire插件配置执行测试,您可以通过测试目标的argLine配置条目设置在运行时使用的所需Java选项.这里有一个官方的例子.下面的第三点也显示了一个例子.

插件配置:通过属性(和配置文件),
您可以结合上面两个选项(在常见的Java选项的情况下)的属性值传递给双方compileArgsargLine配置条目或具有每个配置的不同属性(根据您的需要).

<property>
      <jvm.options>-Xmx256M</jvm.options>
</property>

[...]
<build>
  [...]
  <plugins>
    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-compiler-plugin</artifactId>
       <version>3.3</version>
       <configuration>
         <compilerArgs>
              <arg>${jvm.options}</arg>
         </compilerArgs>
      </configuration>
    </plugin>

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.19.1</version>
       <configuration>
            <argLine>${jvm.options}</argLine>
       </configuration>
     </plugin>
   </plugins>
   [...]
</build>
[...]
Run Code Online (Sandbox Code Playgroud)

使用属性还为您提供了两个额外的优势(在集中化之上):您可以使用配置文件根据不同的所需行为对其进行个性化(例如在此SO答案中),您也可以通过命令行覆盖它们,例如:

mvn clean install -Djvm.options=-Xmx512
Run Code Online (Sandbox Code Playgroud)