Java CLASSPATH environment variable settings

Source: Internet
Author: User

I persistently use command lines to compile and run java programs, so I encountered some problems, but the result was to clarify the essence of the java CALSSPATH environment variables. Although IDE is convenient, command line solves the essence of the computer. After you get started and become proficient, command line will only bring you a higher efficiency and sense of accomplishment. When java needs to outsource the jar package and run a class file that is not in the current directory, the CALSSPATH environment variable must be correctly set to work properly. In fact, the principle is quite simple. I just need to google it and I will find a lot of people who are confused and wrong like me. Some of them must be familiar with the java language and library, it was just a sudden change in the environment that suddenly failed to work and did not know how to solve the problem. In fact, the CLASSPATH environment variable provides a directory prefix for java, which is the same as the current prefix provided by PATH to shell. Java does not know where you put the jar package, so you need to set the jar directory to CLASSPATH. If your project is not a directory like HelloWorld, and the class file is directly in the local directory, you also need to set your project directory to CLASSPATH. Otherwise, when you try to run the class, java will not be able to find it, and an error such as "Exception in thread" main "java. lang. NoClassDefFoundError" will appear. In fact, this error also occurs when you randomly type a java xxx on the command line. One sentence is the directory where the package is located and the directory inside the package. Pay special attention to the issue of "/" when connecting two directories.

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.