At development time, it may be necessary to set different system parameters depending on the environment, and we all know that we can use the-d parameter to set runtime system variables when using the Java-jar command, and how do we set the system variable when running Java programs in eclipse?
In addition, if our program needs to enter a running parameter, how is it configured in eclipse?
The answer is simple, as follows:
Right-click Run As-->run configurations on the class you want to run ...
In the pop-up screen, click Arguments
Then the following screen appears:
1. In the Program arguments column, you can enter the parameters required for the application to run, that is, the parameters of the main method, if the parameters are multiple, separated by a space.
2.VM arguments receives the system variable parameter, the system variable input format is:-dargname=argvalue, similarly, the multiple parameters are separated by a space. In addition, if there are spaces in the middle of the parameter values, enclose them in quotation marks
The sample program code is as follows:
/*** Classname:main <br/> * function:eclipse System variables and operating parameters. <br/> * date:2013-8-27 pm 04:06:09 <br/> * * @author[email protected] *@version */ Public classMain { Public Static voidMain (string[] args) {System.out.println ("Print all the parameters:"); if(args.length>0){ for(inti=0;i<args.length;i++) {System.out.println (The "+i+" parameter is: "+Args[i]); }} System.out.println ("Print system variable:"); String Env= System.getproperty ("service.env"); System.out.println ("Service.env:" +env); String LogPath= System.getproperty ("Logfile.path"); System.out.println ("Logfile.path:" +LogPath); } }
To run the program, the console output is as follows:
- Print all the parameters:
- The first 0 parameters are: Chenzhou
- the first 1 parameters are: CHENZHOU2
- the first 2 parameters are: Chenzhou3
- Print System Variables:
- Service.env:DEV
- Logfile.path:e:\u03\project\logs
Input system variables and run parameters in eclipse