开发者

How to find hidden jar in classpath?

开发者 https://www.devze.com 2023-04-12 10:30 出处:网络
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.ContextLoa

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!


Try following to find location of the jar causing the issue:

System.out.println(org.apache.log4j.Level.class.getProtectionDomain().getCodeSource().getLocation());


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:

for file in *.jar
do
    unzip -l "$file" 2> /dev/null | grep "log4j.dtd" && echo $
done

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消