Tomcat app is loading all of it's code from a jar - where does it say to use that jar?
This Java web-app I am using that other developers wrote is structured in the standard way. However, .class
files are not located under WEB-INF/classes
they are instead grouped together in a .jar and stored under WEB-INF/lib/myapp.jar
.
The issue is that I can't find where the program tells Tomcat to load myapp.jar
for the class file开发者_JAVA百科s. The app is working fine, but how does it know to load that myapp.jar
?
I've tried grep
ping my way through pretty much all conf files (in Tomcat and inside the app), and nowhere I can reference this myapp.jar
file.
Following from what @nhnb said, here's an explanation from Apache on how Tomcat's classLoader works.
WebappX - A class loader is created for each web application that is deployed in a single Tomcat 6 instance. All unpacked classes and resources in the /WEB-INF/classes directory of your web application archive, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application archive, are made visible to the containing web application, but to no others.
So if you want to reference myApp.jar
you must be under the same class loader of that webapp, which essentially means that you have to be in the same webapp.
Alternatively, load your jar in TOMCAT_HOME/lib
(Tomcat 6 and higher) or TOMCAT_HOME/common/lib
. All jars found there are visible to all class loaders.
Tomcat simply loads all .jar files in the WEB-INF/lib folder.
That is actually the default behavior for a Servlet Container.
精彩评论