Servlet containers and classpath

泪湿孤枕 提交于 2019-12-30 06:00:36

问题


To what is the class path of a Servlet container set?

As per my understanding there are three components involved. The JAR files in the lib directory of the Servlet container and then the classes in the WEB-INF/classes and JAR files in the WEB-INF/lib directory. The classes in lib directory of the Servlet container are added to the system classpath and the dynamic classpath includes the JAR files in the lib directory and classes in the classes directory.

To what is the dynamic classpath set? Does the dynamic classpath point to all the directories under WEB-INF or includes all the individual classes and JAR files in WEB-INF/lib and WEB-INF/classes or just points to the two directories WEB-INF/classes and WEB-INF/lib? Say I have a directory called foo in WEB-INF containing bar.properties. Now is bar.properties also in the class path?


回答1:


The "dynamic" classpath will list WEB-INF/classes and each JAR file under WEB-INF/lib as a separate entry. Other folders under WEB-INF are not included.

In your example, bar.properties will not be on the classpath. Move it to WEB-INF/classes, or put it inside a JAR file under WEB-INF/lib.

What's in the rest of the classpath depends on your servlet container. It is implementation-specific, but most containers have two other places to put classes. One is a directory that is visible to the container, but not the applications, and the other is visible to the container and all of the applications. Since the second classloader is visible to all of the applications, static members of those classes can be used to share information between applications.




回答2:


In your example bar.properties would need to be under the classes directory to be in the classpath.



来源:https://stackoverflow.com/questions/305285/servlet-containers-and-classpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!