如何使用pom.xml插件添加VM参数 [英] How to add VM args using pom.xml plugin

查看:307
本文介绍了如何使用pom.xml插件添加VM参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下方法,但没有任何效果... 我正在尝试从服务器远程访问jmx.

I have tried below ways but nothing work... i am trying to access jmx remotely from server.

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

我也尝试过

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

推荐答案

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

You can set Java options for Maven in different points and level (globally or via plugins configuration):

插件配置:仅用于编译
使用 Maven编译器插件配置来编译应用程序代码和测试代码,您可以设置通过compileArgs配置条目所需的Xmx,Xms,Xss选项,可用于编译 testCompile 目标.可以在此处获得一个官方示例. >以及其他类似的答案,例如. 下面也显示了一个示例.

Plugin configuration: just for Compilation
Using the Maven Compiler Plugin configuration for compiling application code and test code, you can set the required Xmx, Xms, Xss options via the compileArgs configuration entry, available for both compile and testCompile goals. An official example is available here and on other SO answers like this one. An example is also shown below.

插件配置:仅用于执行测试
使用 Maven Surefire插件配置来执行测试,您可以设置通过测试目标.可以在此处获得一个官方示例. 下面的第三点也显示了一个示例.

Plugin configuration: just for Tests execution
Using the Maven Surefire Plugin configuration for tests executions, you can set the required Java options to be used at runtime via the argLine configuration entry of the test goal. An official example is available here. An example is also shown below on the third point.

插件配置:通过属性(和配置文件)
您可以将上面的两个选项(在使用通用Java选项的情况下)组合为一个属性值,以同时传递到compileArgsargLine配置条目,或者每个配置具有不同的属性(根据您的需要).

Plugin configuration: via Properties (and profiles)
You can combine the two options above (in case of common Java options) as a property value to pass to both compileArgs and argLine configuration entry or have different properties per configuration (according to your needs).

<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>
[...]

使用属性还为您带来了两个额外的优势(在集中化之上):您可以使用配置文件,然后根据不同的期望行为对其进行个性化设置(例如

Using properties gives you also an two extra advantages (on top of centralization): you can use profiles then to personalize it based on different desired behaviours (and example in this SO answer) and you can override them via command line as well, like:

mvn clean install -Djvm.options=-Xmx512

这篇关于如何使用pom.xml插件添加VM参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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