Input system variables and run parameters in eclipse

Source: Internet
Author: User

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:

  1. /*** 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:

    1. Print all the parameters:
    2. The first 0 parameters are: Chenzhou
    3. the first 1 parameters are: CHENZHOU2
    4. the first 2 parameters are: Chenzhou3
    5. Print System Variables:
    6. Service.env:DEV
    7. Logfile.path:e:\u03\project\logs

Input system variables and run parameters in eclipse

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.