Home Java javaTutorial java environment variable settings and java view installation path

java environment variable settings and java view installation path

Dec 17, 2016 pm 01:24 PM

Friends who use Java development may know that the environment variable settings and installation paths in Java vary depending on the system. Let me introduce how to set and view them under Linux and Windows systems.

After installing jdk into the computer, let's set it up so that the java environment can be used. First, right-click on My Computer. Open properties. Then select "Environment Variables" in "Advanced". The system variables in the new opening interface need to set three attributes: "JAVA_HOME", "path", and "classpath", among which in an environment where jdk has not been installed. The path attribute originally exists. And JAVA_HOME and classpath do not exist.

1: Click "New", then write JAVA_HOME in the variable name. As the name implies, the meaning of this variable is the installation path of java, haha, then write the path just installed "C:\jdk1.6" in the variable value ". (Note: If the installation path is not disk C or is not in the jdk1.6 folder, it can be modified accordingly. The following text is assumed to be installed in C:\jdk1.6.)
Two: Next, find the path in the system variable , and then click Edit. The meaning of the path variable is that the system can recognize the java command in any path, and the variable value is ".;%JAVA_HOME%\bin", (where "%JAVA_HOME%" means the value of JAVA_HOME just set ), you can also directly write "C:\jdk1.6\bin"
Three: Finally, click "New", and then write classpath on the variable name. The meaning of this variable is the path to load the class (class or lib) for java , only if the class is in the classpath, the java command can recognize it. The value is ".;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\toos.jar (add . to indicate the current path)", which is the same as "%JAVA_HOME% has the same meaning"

the above three After the variables are set, press "OK" until the properties window disappears. The next step is to verify whether the installation is successful. First open "Start" -> "Run", type "cmd" to enter the dos system interface. Then hit "java -version" if the installation is successful. The system will display java version jdk "1.6.0".
Make sure the file name installed on the C drive is jdk1.6. Just copy the environment variable directly. Enter javac in the dos interface to check whether the command is legal. Enter java to check whether the command is legal.

windows:

set java_home:查看JDK安装路径
java -version:查看JDK版本
Copy after login

linux:

whereis java
which java (java执行路径)
echo $JAVA_HOME
echo $PATH
Copy after login

Two: The following are the environment variables for configuring linux: (remember source .bash_profile)
. Modify the /etc/profile file (global for all users)


vi This file /etc/profile
is added at the end of the profile file :

export JAVA_HOME=/usr/share/jdk1.6.0_20
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Copy after login

. Modify the .bash_profile file (a certain user has permission to use these environment variables)
Add at the end of the .bash_profile file:

export JAVA_HOME=/usr/share/jdk1.6.0_20
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
.shell终端执行下列命令: (临时用)
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
Copy after login

In this way, the environment variables are set. Let’s explain PATH, CLASSPTH, JAVA_HOME

below For the purpose of setting JAVA_HOME, CLASSPATH, PATH:
1. Set JAVA_HOME:
1. For convenience of reference, for example, if your JDK is installed in the C:\Program Files\Java\jdk1.6.0 directory, set JAVA_HOME as the directory path , then when you want to use this path in the future, just enter %JAVA_HOME% to avoid entering a long path string for each reference;
2. The principle of normalization, when your JDK path is forced to change, you You only need to change the variable value of JAVA_HOME. Otherwise, you will have to change any document that uses an absolute path to reference the JDK directory. If you do not change everything, a certain program cannot find the JDK, and the consequences can be imagined - ---System crash!
3. Third-party software will reference the agreed JAVA_HOME variable. Otherwise, you will not be able to use the software normally. You will know after using JAVA for a long time. If a certain software cannot be used normally, you might as well think about it. Is this the problem?

2. Set CLASSPATH:
This is a very interesting problem, and of course it also tortures beginners. The purpose of setting this variable is so that the program can find the corresponding ".class" file. Let's give an example. : If you compile a JAVA program ---A.java, you will get a class file of A.class. If you execute java A in the current directory, you will get the corresponding results (provided that you have set CLASSPATH to ".") . Now, if you move A.class to another directory (for example: "e:\") and execute java A, there will be a NoClassDefFindError exception because the .class file cannot be found. Now you increase CLASSPATH to :".;e:\"Run java A again and see what the results will be~~:)~~~, everything is normal, the java command found the .class file through CLASSPATH!

3. Set PATH:
It makes sense Simple, do you want to use %JAVA_HOME%\bin\java to execute java commands at any time? Of course not, so you can choose to add %JAVA_HOME%\bin to the PATH path. In this way, we can execute java commands in any path. You can just use java to execute the command. (When you enter your code in the command prompt window, the operating system will search for the corresponding application in the current directory and the PATH variable directory, and execute it.


3. Uninstall jdk
·Find the _uninst subdirectory of the jdk installation directory
·Execute the command ./uninstall.sh in the shell terminal to uninstall jdk.



For more articles related to java environment variable setting and java viewing installation path, please pay attention to the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? Apr 19, 2025 pm 09:51 PM

When using TKMyBatis for database queries, how to gracefully get entity class variable names to build query conditions is a common problem. This article will pin...

See all articles