Original: script for automatically setting Java environment variables on windows
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 @echo off2 3 ::TODO: Setting Java environment Variables4 ::AUTHOR:GWT5Color 026 ::Set the Java installation path to easily switch between different versions7 Setinput=8 Set/P "input= Please enter the JDK path for Java (or enter the default path to C:\Program files\java\jdk1.7.0_71):"9 ifDefined input (EchoJDK is set)Else(SetInput=c:\programFiles\JAVA\JDK1.7.0_71)Ten EchoJDK path is%input% One SetJavapath=%input% A - ::if so, remove Java_home first . -WMIC environment where "name= ' Java_home '"Delete the - ::if so, remove Class_path first . -WMIC environment where "name= ' Class_path '"Delete - + ::Create Java_home -WMIC environment Create Name= "Java_home", username= "<system>", variablevalue= "%javapath%" + A ::Create Class_path atWMIC environment Create Name= "Class_path", username= "<system>", variablevalue= ".; %%java_home%%\lib\tools.jar;% - -%java_home%%\lib\dt.jar; " - - ::in the environment variable path, remove the character from the variable java_home and echo the remaining string - Pager Setxx=%Path%;%java_home%\jre\bin;%java_home%\bin in - ::Echo%xx% to + ::re-assigns the returned characters to the path -WMIC environment where "name= ' Path ' and username= ' <system> '"SetVariablevalue= "%xx%" the * Pause
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
Scripts for automatically setting Java environment variables on windows