Influence of Java environment variables on Java program Compilation

Source: Internet
Author: User

Java environment variablesProgramImpact

 

Java_home =/opt/Java/jdk1.6.0 _ 13
Classpath =.: $ java_home/lib: $ java_home/JRE/lib
Path =.: $ path: $ java_home/bin: $ java_home/JRE/bin

The environment variable classpath is closely related to Java program development,
When you use javac to compile a Java program, the compiler searches for related classes in the path set by classpath,
For example, if the. Class is configured in classpath, that is, the current directory, the compiler will find the corresponding class from the current directory,
For example:

[Root @ localhost perfanalyzer] # ls test/javatest/
Datacollector. Class javatest. jar test. Class
Datacollector. Java manifest. MF test. Java

If the environment has changed and classpath is not configured, the following error occurs during compilation because datacollector will not be searched from the current directory after compilation,
If it is configured, the compilation is normal:

Test Java: Execute./test/javatest/test. Java
Test. Java: 23: The symbol cannot be found.
Symbol: Class datacollector
Location: class test
Datacollector collector = new datacollector ();

In addition, note that the environment variable classpath should be configured to the underlying path of the relevant package,
For example:
* **/Lib has many *. jar package. If you configure classpath at the ***/lib directory level, the compiler will not automatically search for classes in the jar package under the lib directory, it will only find * in the lib directory *. java. In this case, the absolute paths of all jar packages must be appended to classpath one by one, so that the compiler will automatically parse the jar package and find the relevant classes in it.

However, for the JDK library file jar, in $ java_home/lib, mainly tools. jar and DT. Jar
[Root @ localhost lib] # ls *. Jar
DT. Jar htmlconverter. Jar jconsole. Jar sa-jdi.jar tools. Jar

It seems that you do not need to point to the absolute path of the jar

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.