Classpath and environment variable settings

Source: Internet
Author: User

Before setting environment variables, we can directlyProgramAdd relevant information to run us

Program. For example, we can start to run a Java program as follows:

 C: \ jdk1.3.1 \ bin \ Java-jar c: \ windows \ Desktop \ myfiles \ simplecolorconverter. Jar

This is certainly no error. Every time we have to knock on the full path of the Java application and the full path of the class file, we

It's okay to write it once. We don't feel long or tired twice. But if we need to repeat this pile of paths each time,

That would be a nightmare. So how can we reduce our input?

I. Introduction:

Environment variables are designated lights for Operating Systems, Applications, script programs, and so on, which can tell them where the resources they need are. Most

The system has some preset environment variables. Of course, we can also add our own environment variables.

To check the environment variables of the current system, run the following command:

On Linux/Unix systems, enter env in the shell command, and press ENTER

In Windows, enterSetAnd press Enter.

In this way, we can see all the environment variables in the system. What if we want to see the values of a single variable?

On Linux/Unix systems, enter the echo $ variable name in the shell command, and press ENTER

In Windows, enterSet variable or ECHO % variable %And press Enter.

To set an environment variable, run the following command:

On Linux/Unix systems, enter the export variable name = "variable value" in the shell command, and press ENTER

In Windows, enterSet variable name = "variable value"And press Enter.

In this way, the settings are complete. The values of path and classpath are ordered directories. Tell the system or application

Where to find the resources they need. This directory list is separated by a series of delimiters. in Linux/Unix systems, the Delimiter is the colon ":".

In Windows, the semicolon ";" is used. If we want to add some of our own values under an existing environment variable value, we can do this:

In Linux/Unix: Export classpath = $ classpath:/path/to/Program

In Windows: Set classpath = % classpath %; C: \ path \ To \ Program

2. Set the Java environment

To easily develop and run Java applications, we need to set two environment variables, one path and one classpath.

Set the PATH variable so that we can run Java applications, such as javac, Java, and javah, anywhere in the system.

Find the JDK installation directory. For example, if JDK is installed in the C: \ jdk1.3 \ directory, then in the C: \ jdk1.3 \ bin directory

The following is a common Java application. We need to add the c: \ jdk1.3 \ bin directory to the path environment variable.

Classpath environment variables are used to let the Java interpreter know where to reference classes written by others when developing Java programs.

Find this class. Sun usually provides some additional class packages, DT. jar, tools. jar, and these two jar packages.

Both are in the C: \ jdk1.3 \ lib directory, So we usually add these two jar packages to our classpath environment variables.Medium(I am skeptical about this. These two packages should be useless)

Set classpath =.; C: \ jdk1.3 \ Lib \ tools. jar; C: \ jdk1.3 \ Lib \ DT. jar. Note that for jar packages

You must keep up with the complete file path, instead of just a directory. Click "." In the first path to represent the current directory. In this way, when we run Java Aclass

The system will first find the Aclass file in the current directory.

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.