【发布时间】:2016-05-30 11:54:13
【问题描述】:
在 Eclipse 中,我已将 -ea(启用断言)设置为我的 JRE 的 default VM argument。这使得使用断言更加有用,我不想错过它。
但是,在极少数情况下我不想要-ea。有没有办法覆盖(删除)特定运行配置的默认 VM 参数?
具体来说,我想使用 Maven exec:java 运行配置运行 JMH,但是适用于任何类型运行配置的解决方案也很好。
【问题讨论】:
在 Eclipse 中,我已将 -ea(启用断言)设置为我的 JRE 的 default VM argument。这使得使用断言更加有用,我不想错过它。
但是,在极少数情况下我不想要-ea。有没有办法覆盖(删除)特定运行配置的默认 VM 参数?
具体来说,我想使用 Maven exec:java 运行配置运行 JMH,但是适用于任何类型运行配置的解决方案也很好。
【问题讨论】:
您可以在没有 -ea 参数的情况下在 Eclipse 中创建新的 JRE(但安装路径相同)。
然后,对于启动配置,您可以指定要使用的 JRE。
【讨论】:
Maven 配置文件呢?
以下示例针对不同的配置文件使用不同的JDK:
<build>
<plugins>
<!-- we want JDK 1.6 source and binary compatiblility -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- ... -->
<!-- we want sources to be processed by a specific 1.6 javac -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<verbose>true</verbose>
<fork>true</fork>
<executable>${JAVA_1_6_HOME}/bin/javac</executable>
<compilerVersion>1.3</compilerVersion>
</configuration>
</plugin>
</plugins>
</build>
如果您的开发人员只是在他们的settings.xml 中添加(和自定义)以下行,那么您的 pom 将独立于平台:
<settings>
[...]
<profiles>
[...]
<profile>
<id>compiler</id>
<properties>
<JAVA_1_4_HOME>C:\Program Files\Java\j2sdk1.4.2_09</JAVA_1_4_HOME>
<JAVA_1_6_HOME>C:\Program Files\Java\j2sdk1.6.0_18</JAVA_1_6_HOME>
</properties>
</profile>
</profiles>
[...]
<activeProfiles>
<activeProfile>compiler</activeProfile>
</activeProfiles>
</settings>
以下参考 Maven 传递给编译器插件 JVM args...但我从未尝试过:
【讨论】: