简体   繁体   中英

Classes not loading from Jar file on TomCat

I'm trying to migrate from webLogic to Tomcat and Created 2 Dynamic projects, Project 1 and Project 2. Project 1 is deployed on Tomcat but needs resources of project 2 to run.

I below few lines of code in web.xml

<display-name>project 1</display-name>
<description>Project 1 Application</description>

<!-- Http session monitor -->
<listener>
    <listener-class>HttpSessionMonitor</listener-class>
</listener>

But when I start tomcat I get "No Class Def found Error"

I have tried the below methods to fix the issue but none of them worked.

  1. Added the Jar file of Project 2 in Build path of Project 1.
  2. Added the Jar file of project 2 in Deployment Assembly of project 1, the jar file of project 2 ie, project2.jar shows up in WEB_INF/lib folder.
  3. Created a new folder in project 1 and linked the resources of Project 2

Any suggestions for this error? My project 1 is so tightly dependent of project 2 that without project 2 , 1 is so dumb.

I found my own answer after some more research.

Tomcat class loader is loading resources in below order

Therefore, from the perspective of a web application, class or resource loading looks in the following repositories, in this order:

  • Bootstrap classes of your JVM
  • /WEB-INF/classes of your web application
  • /WEB-INF/lib/*.jar of your web application
  • System class loader classes (described above)
  • Common class loader classes (described above)

If the web application class loader is configured with then the order becomes:

  • Bootstrap classes of your JVM
  • System class loader classes (described above)
  • Common class loader classes (described above)
  • /WEB-INF/classes of your web application
  • /WEB-INF/lib/*.jar of your web application

When I placed my class file in the WEB-INF/classes folder, it started working.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM