Use batch processing in Windows to automatically set the Java environment

Source: Internet
Author: User
You have time to write a simple bat script to automatically set the Java 2 SDK environment variables. copy the code and save it as setjava. BAT. after installing the Java 2 SDK, open a command line window, assuming setjava. bat is saved to G:/, and Java 2 SDK is also installed to the G:/JDK directory. Then, start the command line window and enter
G:
Press enter to display
G:/>
Enter
G:/> setjava. Bat G:/JDK
Note: JDK is the installation directory of Java, which contains several files: JRE, bin, and Lib. It does not need to contain the final path. If the installation path contains spaces, use setjava. bat "G:/Java JDK" format and run. setxis the setx.exe program. It is in winnt/system32/or Windows/system32, because the directory is automatically added to the path, therefore, the command line is certainly executable .) after running, JDK settings will be added to the user's environment variables. "*" do not write to bat.
********************
@ Echo JDK installation directory: % 1
@ Echo off
If exist "% 1/bin/java.exe" Goto doset
If "% 1" = "" Goto non
: Doset
@ Setx java_home % 1
@ Setx PATH % java_home %/bin; % PATH %
@ Setx classpath %; % java_home %/lib/tools. Jar
@ Setx classpath %; % java_home %/lib/dt. Jar
@ Setx classpath %; % java_home %/JRE/lib/RT. Jar
@ Setx classpath % ;.
@ Echo on
@ Echo Java 2 SDK environment parameters are set. Press any key to exit normally.
@ Pause
Goto end
: Non
@ Echo on
@ ECHO does not provide the java2sdk installation directory and does not set anything. Please press any key to exit the environment settings.
@ Echo the java2sdk installation directory is invalid without any settings. Press any key to exit the environment setting.
@ Pause
: End
Exit
*******************
After the installation is successful, enter javac in the command line and set the JDK environment variable, if you are familiar with the batchcompute command line, you can add more environment settings, such as Tomcat environment variables. Please change the settings on your own.

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.