Re-learning java basics (1): PATH and CLASSPATH, javaclasspath

Source: Internet
Author: User

Re-learning java basics (1): PATH and CLASSPATH, javaclasspath

I think most beginners of Java will encounter problems, that is, how to configure the environment, execute java-jar xxx. jar will report NoClassDefFindError, I also encountered these problems when I first started learning.

1. PATH path indicates the path. When we run a program directly on the console, the system will go down to the specified PATH to find whether the program exists. If there is a program executed, an error or prompt will be reported. In windows, use echo % PATH % to view the PATH under PATH in linux. After we add the java bin directory to the path using echo $ PATH, you can directly execute the control input java command without entering the bin directory of java. 2. By setting the path, CLASSPATH can execute java commands in any directory. But how does jvm know where the class I want to execute is? This is solved by setting classpath. Several ways to set classpath variables: 1 ). set through the Environment Variable Window 2 ). set CLASSPATH = 3) in the command line ). when executing the java command, set java-classpath = our most common configuration is to set classpath = .; to find the class in the current directory. In earlier versions, you have to set lib and lib \ tools. jar. Now, I use JDK and find that you do not need to set it. The system helps you set and complete the class search. We can use the following program to check what jar URL [] urls = sun is loaded by default. misc. launcher. getBootstrapClassPath (). getURLs (); for (int I = 0; I <urls. length; I ++) {System. out. println (urls [I]. toExternalForm ();} rt. jar is a core jar package in java. It basically contains the basic class CLASSPATH we usually use. For JVM, it is equivalent to PATH corresponding to the operating system. The operating system needs to find the program in the specified PATH, JVM needs to find the CLASS in the specified path.

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.