Java environment variables are automatically configured. Well, C # is used to configure JDK,

Source: Internet
Author: User

Java environment variables are automatically configured. Well, C # is used to configure JDK,

When chatting with students, I found that some people were unfamiliar with environment variable configuration when they first came into contact with Java. It may be because you are a beginner and have no deep understanding of some concepts. In the spirit of helping others. I decided to help them. Write a small tool that automatically configures JDK environment variables.

 

In fact, the logic of the entire process is not difficult:

1,Find the jdk installation path(The default value is C: \ Program Files \ Java \ jdkxxx. xxx indicates the version number string ).

2. In Environment VariablesAdd JAVA_HOMEVariable used to mark the jdk path, which is used in the following steps. The value is the jdk folder path found in step 1.

3. In Environment VariablesAdd CLASSPATHVariable used to specify the Class search path. Its value is:.; % JAVA_HOME % \ lib \ dt. jar; % JAVA_HOME % \ lib \ tools. jar;

(Note the. (DOT) before the string, which indicates the current directory. In the search class, the current directory is essential .)

4,Modify the Path variableIn the Path variable, add: % JAVA_HOME % \ bin; % JAVA_HOME % \ jre \ bin ;. These two items are used to specify the relevant command search path. Allows you to execute commands such as javac everywhere.

5. Success.

(For more detailed manual configuration methods, I will not talk much about them once I search for them on the Internet)

 

Now you can determine the main functions of the automatic configuration tool, that isAdd and modify environment variables.

  Since I am familiar with C #, I decided to use C # for Development (it is strange to use "development" for such a simple tool ~).

The Environment variable modification function is provided in C #: Environment. SetEnvironmentVariable (String, String, EnvironmentVariableTarget), which is located in the System namespace.

(Reference: https://msdn.microsoft.com/zh-cn/library/96xafkes (v = vs.110). aspx)

The problem has been solved. Use the above function to modify the environment variables.

The gadgets have been completed and the code is located at: https://github.com/moonlightwatch/JDKEnvironmentSetter

 

If you have any suggestions or comments, please leave a message in the comment area. You are welcome to all kinds of suggestions and ideas. If you have any questions, please leave a message in the comment area to learn and make progress together.

  

  

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.