Passing parameters from the outside to the java

From the outside to pass parameters in several ways java

1. args passed directly transmitted to jvm

2. Use -Dproperty = vlaue environmental parameters passed in java

3. -Xproperty = vlue incoming JVM configuration parameters required to

Code

/**从外部传递参数到java中*/
public class SendParamS {

    /***
     * 从外部传递参数到java中 的几种方式:
     *
     * 1.使用args 传递 直接传递给jvm
     *
     * 2.使用 -Dproperty=vlaue 传入java环境参数
     *
     * 3.-Xproperty=vlue 传入所需的JVM配置参数
     *
     */

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

        //获取使用-D 传入的参数 传参的key要和该Key一致 没有获取到就使用默认值 1024M
        String memory = System.getProperty("memory", "1024M");
        System.out.println("-D 传入的参数 memory的值 = "+memory);

        //-Xms: 设置java应用程序启动时得初始堆大小
        String ms = System.getProperty("ms", "1024M");
        System.out.println("初始堆大小 = "+ms);

    }
}

Packaging Testing

D:\new\spark\target>java -cp test.jar SendParamS a b -Dmemory=2048M -Xms=512M
args[0] = a
args[1] = b
-D 传入的参数 memory的值 = 1024M
初始堆大小 = 1024M

D:\new\spark\target>
D:\new\spark\target>

If you think my article useful for you, please feel free to point praise. Your support will encourage me to continue to create!
I heard that, I point like people eventually find true love!

I heard thumbs up on me, I went into the Forbes list!

The thumbs are an angel!

Like the point people will become beautiful!

Eventually became the point man like IT technology cattle!

Published 33 original articles · won praise 12 · views 3332

Guess you like

Origin blog.csdn.net/IT_BULL/article/details/103840291