How to Set Jvm Arguments in Intellij Idea

How to set JVM arguments in IntelliJ IDEA?

Intellij allows you to specify two types of arguments when running a Java program:

  • VM Options

    • Enables you to modify attributes of the JVM, including stack/heap memory allocation, system properties, GC flags, etc.
  • Program Arguments

    • Values entered here are passed into the String[] parameter of your main method when the program begins.

Sample Image

In the above image, we specify a single system property (under VM Options) named example that has a value of Hello World!.

We also specify two program arguments (under Program Arguments): Hello and World!.

After clicking either the Apply button or the OK button, we can run the following program:

public static void main(String[] args) {
System.out.println(System.getProperty("example"));
System.out.println(args[0] + " " + args[1]);
}

The output of this program is as follows:

Hello World!
Hello World!

To create a Run/Debug Configuration, see: Create and Edit Run/Debug Configurations

How to define default JVM arguments in IDEA?

You have to do it per run type (Application, JUnit test, etc).

In the "edit configurations" window ("Run" ▸
"Edit Configurations..."), expand the "Defaults" item, select the appropriate run type, and edit its defaults in the left pane.

The full documentation is available in the IDEA docs.

How to set JVM options for IntelliJ's RemoteMavenServer?

Anton's answer is no longer correct. IntelliJ 12.0.1 introduced a new UI for configuring the VM arguments of the RemoteMavenServer process instead of using MAVEN_OPTS:

File -> Settings -> Maven -> Importer -> VM options for maven import process

IntelliJ IDEA VM options

As runIde has the type RunIdeTask which extends Gradle's JavaExec task, you can use usual jvmArgs to configure launched JVM instance.

So, the following should remove the warning.
Groovy DSL:

runIde {
jvmArgs '--add-exports', 'java.base/jdk.internal.vm=ALL-UNNAMED'
}

Kotlin DSL:

tasks.runIde {
jvmArgs("--add-exports", "java.base/jdk.internal.vm=ALL-UNNAMED")
}

Not that it changes much as yole mentioned in the comment.

How do I make IntellIJ use JVM options for all main files in a project?

You can change the configuration under Defaults node (Templates in the new versions), all the new configurations will inherit its settings. Make sure to change the correct default configuration type, Application is most likely what you need.

application

Refer to the documentation for details.

Intellij IDEA: Pass java command arguments

JVM arguments must be added to the "VM options" field:

java <some intellij stuff> <VM options> <Main class> <Program arguments>

IntelliJ adding additional jvm parameters but where?

You can simply create maven configuration with custom parameters. Check http://www.jetbrains.com/idea/webhelp/creating-maven-run-debug-configuration.html



Related Topics



Leave a reply



Submit