Original address: http://chenzhou123520.iteye.com/blog/1931670
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:
Java code
- /**
- * 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 class Main {
- public static void Main (string[] args) {
- System.out.println ("Print all Parameters:");
- if (args.length>0) {
- For (int i=0;i<args.length;i++) {
- System.out.println ("+i+"parameters are: "+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:
Console code
- print all parameters:
- 0 parameters are:chenzhou
- 1 parameters are: chenzhou2
- 2 parameters are: chenzhou3
- Print system variable:
- service.env:dev
- Logfile.path:e:\u03\project\logs