The difference between the build Path import package in Eclipse and the copy to Lib package

Source: Internet
Author: User
Tags java web

The Java build path is the package we need to compile, such as when importing ***.***.*** without the Java Build Path import package, the class has a red fork that does not recognize this class, Build Path is simply a reference to the build of a project to a locally stored package and does not copy the package into the project.

Copy to Lib is the package that the program needs to run, even if the package imported by Java Build Path is not put into Lib, the classnotfoundexception exception will occur when running the project.

following content excerpt from: http://s343174147.iteye.com/blog/1986307

In the case of a Java Web project, it was eventually not run through the local JRE, but instead deployed to Web servers such as Tomcat, Weblogic, WebSphere, and so on, all of which implemented their own classloader.
such as the Tomcat application server, it has its own classloader, according to the specifications of the Java%web-project%/web-inf/lib to find the appropriate LIB, which is why we publish the Web application to conform to that format
As an example of the tomcat typical result, its directory structure corresponds to four different classloader, the relationship is as follows:

Common---Commonclassloader

Server---Catalinaclassloader

Shared---Sharedclassloader

WebApps---WebappClassLoader

Our web applications are deployed to the WebApps directory, and the WebappClassLoader loader is specifically responsible for loading class libraries and class files under Web-inf for all Web projects under WebApps. The jar package we introduced through build path is naturally not loaded by the WebappClassLoader loader, so classnotfoundexception will appear.

Eclipse references the library to compile code to generate the class file in the web-inf/classes, and when using the Eclipse Java EE IDE, all lib in the Web-inf/lib is automatically added to the library
The library under Eclipse Engineering is used to compile the Java files inside the SRC
When actually published to Tomcat, only the jar packages inside the web-inf/lib are copied, so eclipse can compile properly, but Tomcat runs without the class being found.

The difference between the build Path import package in Eclipse and the copy to Lib package

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.