How to set JVM arguments in IntelliJ IDEA?

74,763

Solution 1

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.

enter image description here

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

Solution 2

Follow steps below if you have 2021.1.1 Community Version:

enter image description here

Share:
74,763

Related videos on Youtube

Feihua Fang
Author by

Feihua Fang

Keep producing bugs, keep fixing bugs!

Updated on December 17, 2021

Comments

  • Feihua Fang
    Feihua Fang over 2 years

    I am confused about the instruction when using Kinesis Video Stream

    Run DemoAppMain.java in ./src/main/demo with JVM arguments set to

    -Daws.accessKeyId={YourAwsAccessKey} -Daws.secretKey={YourAwsSecretKey} -Djava.library.path={NativeLibraryPath}
    

    for non-temporary AWS credential.

    How to set these arguments in IntelliJ IDEA?

  • Gaurav
    Gaurav over 4 years
    any example for passing them?
  • Jacob G.
    Jacob G. over 4 years
    @gaurav I’ll edit this answer later today to make it more clear.
  • Ráfagan
    Ráfagan over 2 years
    Man, you deserve a prize
  • Bahodir  Boydedayev
    Bahodir Boydedayev over 2 years
    This is crazy lol. I spent literally an hour for this. Thanks a lot!
  • Frederic Mamath
    Frederic Mamath over 2 years
    Wow ! Exactly same as @BahodirBoydedayev. I lost like an hour before landing on that answer ! Thanks man !
  • Geoff Langenderfer
    Geoff Langenderfer over 2 years
    does VM options accept comma seperated list? Or spaces like on the command line?
  • Detached
    Detached over 2 years
    Yes man, you deserve a prize! Top! Also intellij deserves a prize, epic fail of the decade.

Related