Is it possible to set up project-wide VM arguments in Eclipse

5.6k views Asked by At

I'm using Eclipse, and I need to pass a set of VM arguments to my run configurations. I know how to do it individually using "Run/Debug Settings". And I know how to do it systemwide using Window/Preferences/Java/Installed JREs.

My problem is that I have multiple projects that require different VM arguments. Also, within each project, I have a number of classes to run, so if I go with "Run/Debug Settings" route, duplicating run configurations would be tedious. Even more tedious would be changing individual values inside all of these configurations when I have to make such change.

Is there any way to maintain project-specific run configurations in Eclipse?

2

There are 2 answers

3
fabfas On BEST ANSWER

Window → Preferences → Java → Installed JREs

First Configuration:

Default VM Arguments: -XX:+HeapDumpOnOutOfMemoryError 

JRE Home: JRE1-PorojectType (You can name it anything)

Second Configuration:

Default VM Arguments: -XX:HeapDumpPath=${DOMAIN_HOME}/logs/mps"

JRE Home: JRE2-PorojectType (You can name it anything)

Associate the configured JRE to relevant project, then project will have the default configured VM arguments.

4
Christopher Schneider On

The question wasn't clear initially, but the asker is looking for a way to specify VM arguments for unit tests.

In the case that you need specific VM arguments, you shouldn't rely on Eclipse and prefer a build tool like Maven or Gradle. If your workspace is corrupted (It happens occasionally, for whatever reason) your configurations are all gone.

Using Maven Surefire, you can specify VM arguments to run when executing unit tests on a per-project basis. Not only that, this is IDE agnostic.

You could define it this way in your pom.xml, for example:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.19.1</version>
    <configuration>
        <argLine>-XX:MaxPermSize=1024m</argLine>
    </configuration>
</plugin>

-- Run configurations are already project specific. Right click the project, select Run As, then Run Configurations at the bottom of the menu. You specify which project they apply to when creating them:

Run Configuration

You can specify VM arguments in the Arguments tab, and you can duplicate run configurations by right clicking them and selecting duplicate.