如何在类路径中找到隐藏的jar?
我有一个带有 Spring、Hibernate 和 Struts 2 的网络应用程序,我收到此错误:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchFieldError: TRACE
所以我用 google 搜索,发现 这 说:
如果您在 Equinox 控制台上,请执行以下检查: 包 org.apache.log4j
我这样做了,得到了这个:
org.apache.log4j; version="1.2.15"<org.apache.log4j_1.2.15.v201005080500 [33]>
org.apache.velocity_1.5.0.v200905192330 [37] imports
我真的不知道这意味着什么......但我确信那个罐子不是我的那个罐子我应该正在使用。
事实上,我在删除项目和 Tomcat 库中的所有 log4j jar 后运行了 packages 命令。
即使删除 log4j jar 后,我仍然可以在项目中的任何类中导入 org.apache.log4j.Level 类(当然,我可以导入的 Level 类没有 TRACE 字段)。
那么,我如何找到它在哪里呢?它如何包含在我的项目类路径中???
谢谢您的宝贵时间!
I have a web app with Spring, Hibernate and Struts 2 and I get this error:
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.NoSuchFieldError: TRACE
So I googled it, found this wich says:
if you are on the Equinox Console, perform the following check:
packages org.apache.log4j
Which I did, and got this:
org.apache.log4j; version="1.2.15"<org.apache.log4j_1.2.15.v201005080500 [33]>
org.apache.velocity_1.5.0.v200905192330 [37] imports
And I don't really know what that means... But what I'm sure of is that jar is NOT the one I'm supposed to be using.
In fact, I ran the packages command after I deleted all the log4j jars in the project and in the Tomcat libraries.
And even after deleting the log4j jars, I can still import the org.apache.log4j.Level class in any class in my project (and of course that Level class that I can import doesn't have the TRACE field).
So, how do I find where it is? And how does it get included in my project classpath???
Thank you for your time!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作来查找导致问题的 jar 的位置:
Try following to find location of the jar causing the issue:
jvm 参数“-verbose”或“-verbose:class”将在控制台上输出加载它的每个类(在大多数情况下是哪个 jar)。也许您可以使用它(取决于您运行网络应用程序的方式)。
对于 log4j,请记住,许多人都将 log4j 与他们的 jar 一起提供。理想情况下,如果他们这样做,他们应该更改包名称,但有些人没有这样做。我编写/组装了以下bash脚本来查找我使用的哪个jar中有log4j:
这会查找我正在寻找的log4j.dtd(可以随意替换为任何log4j类),然后打印zip文件中的路径和之后是包含它的 zip 文件的名称。只需从包含所有 jar 的目录中运行它即可。
The jvm argument '-verbose' or '-verbose:class' will output on the console for each class where it is loaded from (in most cases which jar). Possibly this is available to you (depending on how you run the webapp).
For log4j keep in mind that many people ship log4j with their jar. Ideally they should change the package name if they do that, but some don't. I wrote/assembled the following bash script to find which jar I used had log4j in it:
This looks for log4j.dtd which I was looking for (feel free to replace with any log4j class) and then prints the path in the zip file and after that the name of the zip file that contains it. Just run it from the directory with all your jars.