CLASSPATH and environment variable settings

Source: Internet
Author: User

Before setting the environment variable, we can run our data by adding relevant information directly to the application.

The program. For example, we can start running a Java program like this:

C:\jdk1.3.1\bin\java-jar C:\windows\desktop\myfiles\SimpleColorConverter.jar

So surely there is no mistake, every time we have to knock on the full path of the Java application and the classpath of the class file, we

Write once no problem, two times do not feel long, three times do not feel tired, but if we have to repeatedly knock on this pile of paths,

It's really going to be a nightmare. So what can we do to reduce our input?

First, Introduction:

Environment variables are the indicated lights of the operating system, applications, scripts, and so on, telling them where they need to be. Most of

The system has some pre-set environment variables, and of course, we can add our own environment variables as well.

To look at the environment variables of the current system, we can use the following command:

On the Linux/unix system, enter ENV in the shell command, and then enter

In Windows system, enter set at the DOS window prompt , and then enter

So that we can see all the environment variables in the system, if we want to see the value of a single variable?

On the Linux/unix system, enter the echo $ variable name in the shell command, and then enter

In Windows system, enter the set variable or echo% variable at the DOS window prompt, and then enter

If you want to set an environment variable, you can use the following command:

On the Linux/unix system, enter the export variable name = "Variable Value" in the shell command, and then enter

In Windows system, enter the set variable name = "Variable Value" at the DOS window prompt , and then enter

That way, it's set up. The values of the path and CLASSPATH environment variables are some sequential directory listings. Tell the system or application

Where to find the resources they need. This directory list is separated by a series of delimiters, and the delimiter under the Linux/unix system is a colon ":"

A semicolon ";" in the Windows system. If we want to add some of our own values to an already existing environment variable value, you can:

Linux/unix system: Export classpath= $CLASSPATH:/path/to/program

Under Windows system: Set CLASSPATH =%classpath%;c:\path\to\program

Second, set up the Java environment

To facilitate the development and running of Java applications, we need to set up two environment variables, one path and one classpath.

Set the path variable so that we can run Java applications anywhere in the system, such as Javac, Java, Javah, etc.

This will find the directory where we installed the JDK, such as our JDK installed in the c:\jdk1.3\ directory, then in the C:\jdk1.3\bin directory

Is the Java application we use, we need to add the C:\jdk1.3\bin directory to the PATH environment variable.

The CLASSPATH environment variable is when we need to refer to a class that someone else has written when developing a Java program, so that the Java interpreter knows where

To find this class. In general, Sun provides us with some extra rich class packages, one is Dt.jar, the other is Tools.jar, and these two jar packages

are located in the C:\jdk1.3\lib directory, so we usually add these two jar packages to our CLASSPATH environment variable (I doubt that these 2 packets should be added or not)

Set classpath=.; C:\jdk1.3\lib\tools.jar;c:\jdk1.3\lib\dt.jar. Note for jar packages, in Classpath

You need to keep up with the full file path, not just a directory. The first path of the point ".", which represents the current directory, so that when we run Java AClass

, the system will first look for aclass files in the current directory.

CLASSPATH and environment variable settings (RPM)

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.