Idea2021.3.2 Set project operation parameter configuration

Idea2021.3.2 Set the configuration of running parameters: Program arguments, Environment variables and VM options.

1. Click Run -> Edit Configurations

2. In the opened window, you can set Program arguments and Environment variables parameters. If you need to set VM parameters, please see the third step to set VM parameters. When setting the Program arguments parameter, separate multiple parameters with spaces, such as: "22" "33" "44".

3. Set the VM options parameters, click Modify options on the right side of the Build and run column -> select Add VM options, and you can see the input box for filling in the VM options parameters.

 

For example, if you want to modify the upper limit of the Integer class cache, you can enter the VM options input box

Fill in: -XX:AutoBoxCacheMax=200 to expand the default upper limit of Integer from 127 to 200.

4. Obtain the set Program arguments and Environment variables parameters in the main function:

public static void main(String[] args) {
        //获取 Program arguments 参数;如果设置了"12" "13" "14"
        for (String arg :args) {
            System.out.println("参数:" + arg);  
        }
        /*
        打印结果:
            参数:12
            参数:13
            参数:14
            */


        //获取环境变量Environment variables;如果设置了e1=100,则enarg="100"
        String enarg = System.getenv("e1");
        System.out.println("e1参数:" + enarg); //e1参数:100
}

Guess you like

Origin blog.csdn.net/hnjcxy/article/details/123791208