Linux configuration Java environment variables (detailed)

I Unzip and install JDK, and enter jdk-6u14-linux-i586.0 under the shell terminal Bin file directory, execute the command/ jdk-6u14-linux-i586. At this time, a protocol will appear. Continue to hit enter. When you ask whether you agree, enter yes and enter. After that, a jdk1 will be generated in the current directory 6.0_ 14 directory, you can copy it to any directory. II Environment variables to be configured 1 Path environment variable. The function is to specify the command search path. When executing the command under the shell, it will look in the path specified by the path variable to see if the corresponding command program can be found. We need to add the bin directory under the JDK installation directory to the existing path variable. The bin directory contains frequently used executable files, such as javac / Java / Javadoc. After setting the path variable, we can execute javac / Java and other tools in any directory. 2. Classpath environment variable. The function is to specify the class search path and use the already written classes. Of course, the premise is that they can be found. The JVM uses classpth to find classes. We need to install DT in the Lib subdirectory under the JDK installation directory Jar and tools Jar is set in classpath. Of course, the current directory is "." Must also be added to the variable. 3. JAVA_ Home environment variable. It points to the installation directory of JDK. Eclipse / NetBeans / Tomcat and other software search java_ The home variable to find and use the installed JDK. III Three methods of configuring environment variables

1. Modify the / etc / profile file

If your computer is only used for development, this method is recommended, because all users' shells have the right to use these environment variables, which may bring security problems to the system· Open / etc / profile with a text editor and add: export Java at the end of the profile file_ HOME=/usr/share/jdk1. 6.0_ 14 export PATH=$JAVA_ HOME/bin:$PATH export CLASSPATH=.:$ JAVA_ HOME/lib/dt. jar:$JAVA_ HOME/lib/tools. Jar · login again · annotation A. you want to add / usr / share / jdk1 6.0_ 14 change to your JDK installation directory B. separate paths with colon ":" under Linux C. $path / $classpath / $Java_ Home is used to reference the value of the original environment variable. When setting the environment variable, pay special attention not to overwrite the original value, which is a common error. d. Current directory '.' in classpath It is also a common mistake to throw away the current directory. e. Export exports these three variables as global variables. f. Case must be strictly distinguished. 2. Modification bash_ Profile file

This method is more secure. It can control the permission to use these environment variables to the user level. If you need to give a user permission to use these environment variables, you only need to modify the permissions in its personal user home directory bash_ The profile file is OK· Open the in the user directory with a text editor bash_ Profile file · in bash_ Add: export Java at the end of profile file_ HOME=/usr/share/jdk1. 6.0_ 14 export PATH=$JAVA_ HOME/bin:$PATH export CLASSPATH=.:$ JAVA_ HOME/lib/dt. jar:$JAVA_ HOME/lib/tools. Jar · re login 3 Setting variables directly under the shell is not in favor of using this method, because if you change the shell, your setting will be invalid. Therefore, this method is only used temporarily and needs to be reset when you want to use it in the future, which is more troublesome. Just execute the following command at the shell terminal: export Java_ HOME=/usr/share/jdk1. 6.0_ 14 export PATH=$JAVA_ HOME/bin:$PATH export CLASSPATH=.:$ JAVA_ HOME/lib/dt. jar:$JAVA_ HOME/lib/tools. Jar IV Test JDK 1 Create a new test with a text editor Java file, enter the following code and save it: public class test {public static void main (string args []) {system.out.println ("a new JDK test!");   } } 2. Compile: execute the command javac test at the shell terminal java 3. Run: execute the command java test on the shell terminal, and "a new JDK test!" appears under the shell The JDK works normally. V Uninstall JDK · find the location of the JDK installation directory_ Uninst subdirectory · execute commands at the shell terminal/ uninstall. SH to uninstall the JDK.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>