In clipse3.2/3.3, take notes on several methods for specifying third-party packages (jar) and classpath)

Source: Internet
Author: User

 

In Java classes, we can reference third-party packages (jar) or third-party classes (class) by using the "Import + package name + class name" method ), however, you have to tell the Java compiling and running environment where to find these libraries or classes. If these are not set, problems such as failure to parse a class or noclassdeffounderror may occur. Therefore, we must use eclipse to specify these paths to tell the Java Development and runtime environment where to find these packages and classes.
1. Specify the jar package through environment variables
Window-> preferences-> JAVA-> build path-> classpath variables, specify the package location with a variable, similar to setting classpath in environment variables. It consists of two parts: one is name, specifying the variable name; the other is file path, specifying the location of the jar package, or folder, specifying the folder where the class file is located. The advantage is that if the location of the package changes, we only need to go back to this place to modify the location of the jar package and class, and the reference to these packages and classes in the project does not need to be modified.
2. Specify multiple jar packages at the same time by creating a user Library
Window-> preferences-> JAVA-> build path-> User libraries, create a user library, you can add multiple jar to it, because there may be multiple projects, each project may reference multiple identical packages (jar) at the same time, and put these packages under the same user libraries, so that each project can only reference this library, this saves the trouble of adding multiple packages to each project each time.
3. Specify the jar used in project development (displayed in referenced libraries of package Explorer ):
Project-> properties-> JAVA build path-> Libraries
There are several ways to add jar packages. Here we will explain them separately.
A, add jars...
Add the jar package in the project to the Reference Path of the project.
Sometimes, we place some third-party packages in the folder of our project (such as a. Jar). Generally, we name this folder Lib. In Windows, create a new folder under workspace \ % project directory %, name it Lib, and copy the. jar file to Lib. Go back to eclipse, right-click package Explorer (package Explorer), and select refresh to view the Lib folder and A. jar file. Then, add jars... to add a. jar to the project reference.
B, add external jars
Add an external jar package to the project. This is not good because once the location of the external jar package is changed, the project must be reconfigured. It is not as flexible as other methods, so it is not recommended.
C, add variables
Add a variable and add the environment variable defined in 1.
D, add Libraries
To add a library, you can add JRE system library and so on. The user library is the user library you created in 2, JUnit can quickly add the packages required by JUnit to the reference of the current project.
E, add class folder
Add the folder where the class is located
4. Specify the jar used at runtime (used at runtime)
Here, the jar has two parts: the JRE jar, the system jar in the runtime environment, and the user entries, the "% project name %" subdirectory contains the jar referenced in referenced libraries in the package explorer view. You can specify the runtime jar here, as long as it is placed before the jar referenced in referenced libraries.
A, run-> open run dialog-> classpath
B, run-> open debug dialog-> classpath

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/ruyanhai/archive/2007/10/16/1826876.aspx

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.