【问题标题】:How to override the default JVM arguments in Eclipse?如何覆盖 Eclipse 中的默认 JVM 参数?
【发布时间】:2016-05-30 11:54:13
【问题描述】:

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

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

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

【问题讨论】:

    标签: java eclipse maven jmh


    【解决方案1】:

    您可以在没有 -ea 参数的情况下在 Eclipse 中创建新的 JRE(但安装路径相同)。

    然后,对于启动配置,您可以指定要使用的 JRE。

    【讨论】:

      【解决方案2】:

      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...但我从未尝试过:

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

      【讨论】:

      • 最好的方法是使用toolchain 而不是属性/配置文件组合。
      • 嗯,我在您的回答中没有看到任何有关 JVM 参数的信息。需要详细说明吗?
      • 是的,正如我所写,这个例子只使用了不同的 JDK,顺便说一下,你可以为 maven 编译器插件指定不同的值,请参阅这个线程:stackoverflow.com/questions/27035389/… 但你可以看到它取决于 MVNand编译器版本,所以无法工作..如果您四处搜索,您还会发现为您执行此操作的插件,或者您可以使用执行安装导出 MAVEN_OPTS 值的 exec 插件运行一个过程,我只是想给你对如何制作它的一些想法..
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-20
      • 2014-01-05
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      相关资源
      最近更新 更多