控制 servlet 中的类路径 [英] Controlling the classpath in a servlet

查看:26
本文介绍了控制 servlet 中的类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 servlet 应用程序包含许多库 .jar,其中一些包含嵌入式 log4j.xml 或 log4j.properties 文件.我想确保 log4j 首先找到我的 log4j.xml!我已经尝试在 servlet 中搜索各种类路径元素的优先级规范(例如,WEB-INF/classes 是否总是在 WEB-INF/lib 之前?),或者某种方式来配置或调整 servlet 的类加载器,以便给定的资源目录出现在类路径的早期.到目前为止,我已经画了一个空白.关于确保 servlet .war 文件通过类加载器加载正确的 log4j.xml 有什么建议吗?

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.xml first! I've tried searching for some specification of the priorities of the various classpath elements in a servlet (e.g. does WEB-INF/classes always precede WEB-INF/lib?), or some way to configure or tweak the servlet's classloader so that a given resource directory appears early in the classpath. So far, I've drawn a blank. Any suggestions on ensuring that a servlet .war file loads the correct log4j.xml via the classloader?

推荐答案

据我所知,从类路径中选择资源是不确定的(从应用程序开发人员的角度来看).即使始终加载相同的文件,行为也可能会改变:1. 当您升级当前容器的版本时.2.如果你切换容器.

As far as I understand the resource selection from the classpath is non-deterministic (from the point of view of the app developer). Even if the same file is loaded consistently the behaviour could change: 1. When you upgrade the version of your current container. 2. If you switch containers.

最简单的解决方案是从库 jar 中删除嵌入的 log4j 配置文件.嵌入 log4j 配置几乎从来都不是一个好主意,因为它会导致您在此处看到的问题...

The simplest solution will be to remove embedded log4j config files from library jars. It is almost never a good idea to embed log4j config's as it leads to the problem you are seeing here...

它们是第三方 jar 还是您开发的 jar?

Are they third party jars or jars you developed?

这篇关于控制 servlet 中的类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆