如何在 Eclipse 中覆盖缺省的 JVM 参数



在 Eclipse 中,我已将-ea(启用断言)设置为我的 JRE 的默认 VM 参数。这使得使用断言更加有用,我不想错过它。

但是,在极少数情况下,我不想-ea.有没有办法覆盖(删除)特定运行配置的默认 VM 参数?

具体来说,我想使用 Maven exec:java运行配置运行 JMH,但适用于任何类型的运行配置的解决方案也会很好。

您可以在 Eclipse 中创建新的 JRE,而无需使用 -ea 参数(但安装路径相同)。

然后,对于启动配置,您可以指定要使用的 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 FilesJavaj2sdk1.4.2_09</JAVA_1_4_HOME>
          <JAVA_1_6_HOME>C:Program FilesJavaj2sdk1.6.0_18</JAVA_1_6_HOME>
        </properties>
    </profile>
  </profiles>
  [...]
  <activeProfiles>
    <activeProfile>compiler</activeProfile>
  </activeProfiles>
</settings>

下面引用Maven传递给编译器插件JVM参数...但我从未尝试过:

https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-with-memory-enhancements.html

最新更新