Controlling the classpath in a servlet

后端 未结 6 468
陌清茗
陌清茗 2020-12-03 09:02

My servlet application includes a number of library .jars, some of which contain embedded log4j.xml or log4j.properties files. I\'d like to ensure that log4j finds my log4j.

6条回答
  •  借酒劲吻你
    2020-12-03 09:32

    Tomcat 8.5

    Ditto Tomcat 8.0.

    See documentation: Class Loader HOW-TO.

    Tomcat 8.0

    The answer is simple, taken from the Tomcat documentation page, Class Loader HOW-TO. In particular notice the use of the /WEB-INF/ directory/folder.

    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

    Tomcat 6

    Excerpted from Tomcat 6 page, Class Loader HOW-TO.

    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
    • System class loader classes (described above)
    • /WEB-INF/classes of your web application
    • /WEB-INF/lib/*.jar of your web application
    • $CATALINA_HOME/lib
    • $CATALINA_HOME/lib/*.jar

提交回复
热议问题