Script to automatically set Java environment variables on "Go" windows

Source: Internet
Author: User

Reprint: http://www.cnblogs.com/flowwind/p/4066146.html

Recently intends to learn the development of Android, so to prepare the Java development environment, install the JDK, it is necessary to set the Java environment variables, Java environment variables to set Java_home,path,classpath three values, each configuration check Baidu copy paste is very troublesome, so think lazy under, The script was executed directly, and the bat command was searched, and a script to configure the Java environment variable was written.

By default, the Java JDK installation path is C:\Program files\java\jdk1.7.0_71, if your JDK installation path is not here, you can execute this command, you will be prompted to enter the JDK installation path, input.

First paste the command as follows:

1@echoOff23::TODO: setting Java environment variables4::Author:gwt5 Color 026::Set the Java installation path to easily switch between different versions7Set input=8set/p "Input= Please enter the JDK path for Java (or return to the default path of C:\Program files\java\jdk1.7.0_71):"9If defined input (Echo JDK is set)Else (Set Input=c:\programFILES\JAVA\JDK1.7.0_71)10EchoJDK Path is%input%11Set javapath=%input%1213::If so, remove Java_home first.WMIC environment where "name= ' Java_home '"Delete1516::If so, remove Class_path first.Environment wmic WHERE "name= ' Class_path '"Delete1819::Create Java_homeWMIC environment Create Name= "Java_home", username= "<system>", variablevalue= "%javapath%"21st22::Create Class_pathEnvironment WMIC Create name= "Class_path", username= "<system>", variablevalue= ".; %%java_home%%\lib\tools.jar;%24%java_home%%\lib\dt.jar; "2627::28 call set xx=%path%; %java_home%\jre\bin;%java_home%\bin29 30 ::echo%xx%31 32 :: re-assigns a character that returns an explicit value to path 

Here's an explanation of the order.

@echo off is turned off, no command information is displayed on open to display command information

Color 02 is to set the output text colors, here is the control command station output green color

set/p "input= Please enter command information" is used to receive the console input text information

If else is used to determine if defined input is used to determine whether the user is entering information or not, then the value of input is undefined

echo "Output information" is used to display the information

The set javapath=%input% is used to assign the value of the variable input to the Javapath variable.

WMIC is a batch command that allows you to easily manipulate the values of environment variables.

Delete an environment variable using WMIC environment where "name= ' java_home '" Delete command

Create an environment variable using WMIC environment create Name= "Java_home", username= "<system>", variablevalue= "%javapath%" command

Modify an environment variable using WMIC environment where "name= ' Path ' and username= ' <system> '" Set variablevalue= "value"

Precautions:

1, in the above batch processing script command, to strictly pay attention to the space and case of input, or do not perform the unsuccessful

2, to run the command as an administrator, or prompt to refuse to execute the command prompt

Script to automatically set Java environment variables on "Go" windows

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.