Controlling the classpath in a servlet

后端 未结 6 471
陌清茗
陌清茗 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:24

    In my experience, WEB-INF/classes typically takes precedence over jars in WEB-INF/lib, however, that also depends on the servlet container you use (I could never figure out the behavior of JRun, for instance). It would help immensely if you could tell me which container you're using.

    Also, are you certain that the offending log4j configuration is in a jar in WEB-INF/lib? Typically, when I've run into classpath problems in a servlet container situation, it's because of libraries that reside outside of the web app.

    The servlet specs recommend that web app classloaders load their own classes before delegating to the container's classloader (SRV.9.7.2), but since this is counter to the Java spec, not all vendors do this by default (in fact Tomcat is the only container I've used that does this by default). With that said, it's always possible to configure your container's web app classloading behavior. If you tell me which container you're using, I may be able to help you (specifically, I have done this successfully before on WebLogic, WebSphere, Glassfish and JRun)).

提交回复
热议问题