Setting JVM Arguments in IntelliJ IDEA: A Comprehensive Guide

Dec 01, 2025 · Programming · 10 views · 7.8

Keywords: JVM arguments | IntelliJ IDEA | VM Options

Abstract: This article provides a detailed guide on how to set JVM arguments in IntelliJ IDEA, explaining the differences between VM Options and Program Arguments, configuration steps, and practical examples to help developers correctly configure environments for applications like AWS Kinesis Video Stream.

Introduction

In Java development, correctly setting JVM arguments is crucial for ensuring the stable operation of applications. Especially when using services like AWS Kinesis Video Stream, it is necessary to pass sensitive information such as AWS access keys through JVM arguments. IntelliJ IDEA, as a popular integrated development environment, offers convenient Run/Debug Configuration to manage these arguments.

Differences Between VM Options and Program Arguments

In IntelliJ IDEA, you can specify two types of arguments for Java programs:

Correctly distinguishing between these types is key to avoiding configuration errors. For instance, in the AWS Kinesis Video Stream example, parameters like -Daws.accessKeyId={YourAwsAccessKey} should be set as VM Options.

Steps to Set JVM Arguments in IntelliJ IDEA

Based on the best answer, the basic steps to set JVM arguments are:

  1. Open IntelliJ IDEA, navigate to the Run menu, and select Edit Configurations....
  2. In the configuration dialog, select or create a Java application configuration.
  3. In the VM options field, enter VM arguments, such as -Daws.accessKeyId={YourAwsAccessKey} -Daws.secretKey={YourAwsSecretKey} -Djava.library.path={NativeLibraryPath}. These are for JVM-level properties.
  4. In the Program arguments field, enter program arguments, which are passed as an array to the main method.
  5. Click Apply or OK to save the configuration, then run the program.

Supplemented by other answers, for IntelliJ IDEA 2021.1.1 Community Version, the interface may vary slightly, but the process is similar and accessible via toolbar or menu options.

Example: Setting AWS Credentials as JVM Arguments

Suppose you need to run a DemoAppMain.java program with non-temporary AWS credentials. Set the VM Options as follows:

-Daws.accessKeyId=your_access_key -Daws.secretKey=your_secret_key -Djava.library.path=/path/to/native/library

In Java code, access these system properties using the System.getProperty() method. For example, rewritten code to demonstrate usage:

public static void main(String[] args) {
    String accessKey = System.getProperty("aws.accessKeyId");
    String secretKey = System.getProperty("aws.secretKey");
    System.out.println("Access Key: " + accessKey);
    System.out.println("Secret Key: " + secretKey);
    // Additional logic handling
}

After running the program, the output will display the set access and secret keys, confirming that VM Options are correctly passed to the JVM.

Conclusion

Mastering how to set JVM arguments in IntelliJ IDEA is a fundamental skill in Java development. By properly configuring VM Options and Program Arguments, you can flexibly manage application runtime environments, enhancing development efficiency and code maintainability. Always ensure parameter types match to avoid runtime errors.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.