The configuration of Java local and global environment variables under Linux

Source: Internet
Author: User

Linux is usually used as a server operating system, in which case, it is impossible to install any development environment, so the development of the application is usually uploaded to use the command to configure all parameters and then start running, there is a problem, Suppose my application is jdk1.5, and the other application is jdk1.6, or the Linux jdk is. 14, how can I make each application without changing the Linux JDK Run under your own JDK, the steps are this:

Of course, first of all, how to configure the environment under Linux, Linux is different from Windows, Its environment variable is configured in a. bashrc or. profile file, using the command env to see all the environment variables, in the. bashrc file, for example, the file is found in headlines record, it is hidden, ctrl+h display, after opening, add the following configuration at the bottom:

Export Java_home = JDK's home directory path

Export PATH = $JAVA _home/bin: $PATH

Export CLASSPATH =.: $JAVA _home/lib

This is configured, pay attention to the path behind must add $path, otherwise your path is only a bin, the previous is covered, resulting in a lot of programs can not use, and then the classpath must be added before. So that the program can be found from the current path, or often reported "no xx category"

Then you can write a simple class and run the test with the Javac,java command. Sometimes use the Java command when the report "Can not find the class you want to run", retrieve, if the environment variables are not a problem, then it may be your permission issues, to see if the current user is not root, If not, add sudo and try, of course, if your class references other things, Java writes like this JAVA-CP ".: Package Path: Package path" XX class, with CP option to add a reference jar package or class, note, if it is a jar, can't use wildcard characters, how many write how many, And then it's still the front ".", absolutely must not be less, the Linux separator is ":", Windows is ";", this should be noted, and then is how to use different JDK, in fact, the above steps with an SH file together on the line, create an SH file, and write the configuration in the following way.

(Refer to the above on the line)

Export Java_home= ...

Export PATH = .....

Export CLASSPATH = .....

JAVA-CP ".:/ Package: Package ..... XX class

This can be done, and then run this SH on the line, these problems are their own encounter, resolved after sharing with you, I hope to help you, oh, yes, if you are created with Eclipse Project, we recommend that the bin directory as a root directory do these operations

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.