4/02/2007

Which4J

Which4J is a simple utility app that helps you determine where classes are being loaded from. This can be especially helpful in debugging classpath and classloader problems. It serves the same general purpose as the Unix which command except it searches your classpath (or a particular classloader) instead of your shell command path.

Which4J can be run in command-line mode to search your system classpath for all occurrences of the specified classname. More importantly, it can also be used programmatically to search a particular ClassLoader for the first occurrence of the specified classname or Class instance. This can be extremely valuable when trying to debug problems in web containers and application servers that have sophisticated ClassLoader hierarchies.

The following snippet of code shows how simple it is to figure out where a particular classloader is loading a particular class from:







System.out.println(org.theshoemakers.which4j.Which4J.which( java.lang.String.class ) );


And here is the output:


jar:file:/D:/jdk1.4.1_03/jre/lib/rt.jar!/java/lang/String.class

Download which4J

2 comments:

Arun said...

this is a real cool one. Need to try this out.

deepthi sajja said...

This is very cool. I've been struggling from past 1 week on a class loader issue and this resolves it. Kudos to you!

Tired of seeing that 500 Bad gateway error while deploying a Springboot application in AWS...?

By default, Spring Boot applications will listen on port 8080. Elastic Beanstalk assumes that the application will listen on port 5000. Th...