0

In Eclipse, I have set -ea (enable assertions) as a default VM argument for my JREs. This makes using assertions much more useful, and I wouldn't want to miss it.

However, there are some rare situations where I don't want -ea. Is there a way to override (remove) the default VM arguments for, let's say, a specific run configuration?

Specifically, I want to run JMH using a Maven exec:java run configuration, but a solution that works for any kind of run configuration would be nice too.

Community
  • 1
  • 1
rolve
  • 10,083
  • 4
  • 55
  • 75

2 Answers2

2

You can create new JREs in Eclipse without the -ea argument (but the same installation path).

Then for a launch configuration you can specify the JRE to use.

rolve
  • 10,083
  • 4
  • 55
  • 75
mvera
  • 904
  • 12
  • 23
-1

What about a Maven profile?

The example below use different JDK for different profile:

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

If your developers just add (and customize) the following lines in their settings.xml, your pom will be platform independent :

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

Below reference to Maven to pass to the compiler plugin JVM args... but i never tried it:

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

ivoruJavaBoy
  • 1,307
  • 2
  • 19
  • 39
  • Best for such things is to use [toolchain](https://maven.apache.org/guides/mini/guide-using-toolchains.html) and not properties/profile combination. – khmarbaise May 30 '16 at 12:23
  • Uhm, I don't see anything about JVM args in your answer. Care to elaborate? – rolve May 30 '16 at 12:33
  • Yes, as i wrote, this example use just different JDK, by the way you can specify for the maven compiler plugin different values see this thread: http://stackoverflow.com/questions/27035389/how-to-set-xxpermsize-64m-in-maven-compiler-plugin But as you can see it depends by MVNand compiler version, so could not work.. if you search around you will find also plugin that do this for you, or you can just run a procedure with the exec plugin that perform the install exporting MAVEN_OPTS values, I'm just trying to give you some ideas about how make it.. – ivoruJavaBoy May 30 '16 at 13:30