Input system variables and run parameters in eclipse--go to

Source: Internet
Author: User

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
  1. /**
  2. * Classname:main <br/>
  3. * Function:eclipse System variables and operating parameters. <br/>
  4. * date:2013-8-27 pm 04:06:09 <br/>
  5. *
  6. * @author [email protected]
  7. * @version
  8. */
  9. Public class Main {
  10. public static void Main (string[] args) {
  11. System.out.println ("Print all Parameters:");
  12. if (args.length>0) {
  13. For (int i=0;i<args.length;i++) {
  14. System.out.println ("+i+"parameters are: "+args[i]);
  15. }
  16. }
  17. System.out.println ("Print system variable:");
  18. String env = System.getproperty ("service.env");
  19. System.out.println ("service.env:" +env);
  20. String LogPath = System.getproperty ("Logfile.path");
  21. System.out.println ("Logfile.path:" +logpath);
  22. }
  23. }

To run the program, the console output is as follows:

Console code
    1. print all parameters:   
    2. 0 parameters are:chenzhou   
    3. 1 parameters are: chenzhou2  
    4. 2 parameters are: chenzhou3  
    5. Print system variable:   
    6. service.env:dev  
    7. Logfile.path:e:\u03\project\logs
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.