Java 如何使用pom.xml插件添加VM参数

Java 如何使用pom.xml插件添加VM参数,java,maven,pom.xml,vmargs,Java,Maven,Pom.xml,Vmargs,我尝试了以下方法,但没有任何效果。。。 我正在尝试从服务器远程访问jmx <jvmArgs> <jvmArg>-Dcom.sun.management.jmxremote.port=9999</jvmArg> <jvmArg>-Dcom.sun.management.jmxremote.authenticate=false</jvmArg> <jvmArg&g

我尝试了以下方法,但没有任何效果。。。 我正在尝试从服务器远程访问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> -->

-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
我也试过了

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

-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false

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

插件配置:仅用于编译
使用用于编译应用程序代码和测试代码的配置,您可以通过compileArgs配置条目设置所需的Xmx、Xms、Xss选项,该条目可用于和目标。一个官方的例子是可用的,其他的答案如。 下面还显示了一个示例

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

插件配置:通过属性(和配置文件)
您可以将上述两个选项(如果是常见Java选项)组合为属性值,以传递给
compileArgs
argLine
配置条目,或者每个配置具有不同的属性(根据您的需要)


要添加哪些vmargs?编译、测试、运行应用程序?你的目标是什么?你应该多展示你的pom。
<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>
[...]
mvn clean install -Djvm.options=-Xmx512