如何使用 pom.xml 插件添加虚拟机参数
How to add VM args using pom.xml plugin
我尝试了以下方法,但没有任何效果...
我正在尝试从服务器远程访问 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> -->
我也试过了
<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 选项:
插件配置:编译用
使用 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。
下面还显示了一个示例。
插件配置:仅用于测试执行
使用 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。
下面第三点也有一个例子。
插件配置:通过属性(和配置文件)
您可以将上面的两个选项(在常见 Java 选项的情况下)组合为 属性 值以传递给 compileArgs
和 argLine
配置条目,或者每个配置具有不同的属性(根据您的需要)。
<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>
[...]
使用属性还为您提供了两个额外的优势(在集中化之上):您可以使用配置文件然后根据不同的期望行为对其进行个性化设置(以及此 SO answer 中的示例)并且您可以覆盖它们也可以通过命令行,例如:
mvn clean install -Djvm.options=-Xmx512
我尝试了以下方法,但没有任何效果... 我正在尝试从服务器远程访问 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> -->
我也试过了
<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 选项:
插件配置:编译用
使用 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。
下面还显示了一个示例。
插件配置:仅用于测试执行
使用 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。
下面第三点也有一个例子。
插件配置:通过属性(和配置文件)
您可以将上面的两个选项(在常见 Java 选项的情况下)组合为 属性 值以传递给 compileArgs
和 argLine
配置条目,或者每个配置具有不同的属性(根据您的需要)。
<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>
[...]
使用属性还为您提供了两个额外的优势(在集中化之上):您可以使用配置文件然后根据不同的期望行为对其进行个性化设置(以及此 SO answer 中的示例)并且您可以覆盖它们也可以通过命令行,例如:
mvn clean install -Djvm.options=-Xmx512