Four Methods for setting Java environment variables

Source: Internet
Author: User
Three environment variables that need to be set frequently in Java:
Java_home, classpath, path
(1) Configure environment variables: (relative path)
1.
Java_home = x:/jdk1.6.0
2.
% Java_home % can replace: X:/jdk1.6.0.
Classpath
.: $ Java_home/lib/tools. jar: $ java_home/lib/dt. jar: $ java_home/lib/activation. jar: $ java_home/lib/mail. Jar
Or
Classpath
.; % Java_home %/lib/tools. jar; % java_home %/lib/dt. Jar
3.
Path
; % Java_home %/bin
(2) Configure environment variables: (absolute path)
1.
Java_home
D:/jdk1.5.0
2.
Classpath
.; D:/jdk1.5.0/lib/tools. jar; D:/jdk1.5.0/JRE/lib/RT. jar;
3.
Path
D:/jdk1.5.0/bin;

(3)
Run the following code in batches, which is convenient for setting environment variables.

@ Echo off
If exist % 1/bin/java.exe (
If REM enters the correct java2sdk installation directory, it starts to set environment variables.
@ Setx java_home % 1
@ Setx PATH %; % java_home %/bin
@ Setx classpath % ;.
@ Setx classpath %; % java_home %/lib/tools. Jar
@ Setx classpath %; % java_home %/lib/dt. Jar
@ Setx classpath %; % java_home %/JRE/lib/RT. Jar
@ Echo on
@ Echo Java 2 SDK environment parameters are set and exit normally.
) Else (
If "% 1" = ""(
If the installation directory is not provided by REM, exit after prompt
@ Echo on
@ ECHO does not provide the installation directory of java2sdk, and does not set anything. Now exit the environment variable settings.
) Else (
Rem if non-empty installation directory is provided but no bin/java.exe is available, the specified directory is the wrong directory.
@ Echo on
@ ECHO: the installation directory of the invalid java2sdk is not set. Now exit the environment variable settings.
)
)

(4) Other Practices
CMD command settings
Set Path = C:/j2sdk1.4.0/bin

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.