Detailed description of the build path of the java project in eclipse, eclipsepath

Source: Internet
Author: User

Detailed description of the build path of the java project in eclipse, eclipsepath

Only jar files can be added to BuildPath. The specific method is as follows:
In eclips, right-click the project name and choose build path> contigure bud path> java build path.
Libraries->

Add external jars = add external project packages
Add jars = add project packages
Add library = add a library
Add class folder = add a class folder

 

 

The following describes the User Libraries in the add library.
To add a User Library, follow these steps:
1. Right-click the project and choose build path> Add Libraries...
2. Select User Library-> next
3. Click the User Library button.
4. Click "new ".
5. Enter the Library name (I want to import the jar package of struts 2.1.6 and the jar package of jdbc. For convenience of memory, you can use Struts 2.1.6 Library, for example)
6. Click OK.
7. Select the user library and click add jars.
8. Find the corresponding jar package and click OK.

 


User Liberary is added to Eclipse, but it takes effect in eclipse, that is, only Eclipse knows where the referenced classes are put, but if you want the web project to start normally,
Tell Tomcat and other containers where your jar package is (in the lib directory, the container will know ). In this case, you can add a user library in eclipse
Try: if you do not add the user library, and eclipse cannot find the import class, a red X number will appear. If you do not put the JAR package in the user Library Under lib, the introduced class will not be found for the capacity, an error is reported.
The differences between add jar and add external jars and User Libraries in add library are:
The jar packages added through "add jar" and "add external jars" are packaged into the final program as part of the program. The jar package added through "User Libraries" is not.

 

About the role of Jar package build path:
The jar package cannot be anywhere. Whether it is Java Application or Java Web Application.
The Java VM decides how to load the Class according to the Java ClassLoader (Class Loader:
We put the jar package under classPath because the ClassPath ClassLoader exists.
We can not specify some Jar packages in ClassPath, but it can also be used in Java programs.
That is because the parent class loader with ClassPath ClassLoader is responsible for loading. For example, jre \ lib \ *. jar under the jrd directory
The reason why we put the Jar package into the lib folder under webroot and can be used in our program is that the container implements its own ClassLoader. (The Web middleware server class loading mechanism is different from the three default loaders provided by sun .)
Therefore, whether the Jar can be loaded or where the Jar is loaded depends on the ClassLoader.

Related Article

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.