简体   繁体   中英

How to find hidden jar in classpath?

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!

尝试按照以下步骤查找引起问题的罐子的位置:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM