Which jars is my java application using?

Kerr_mason_jar

I'm pretty sure that this trick is well known among Linux users. But to me it was quite a revelation. If you issue command

$ ls -l /proc/<PID>/fd

it will list all the open files of a process identified by <PID>.

This comes especially handy when developing java application. A frequent source of problems in java applications is using incorrect version of jars. While situation with jars in java is not as bad as dll hell in Windows, it is not that far off. When debugging a java application, one of the first thing that you should do is to check if your application is using correct version of jars.

Here's partial output for a running instance of Apache Lucene/Solr

$ ls -l /proc/20879/fd

0 -> /dev/null 1 -> /home/user/solr/apache-tomcat-5.5.28/logs/catalina.out ... 18 -> /home/user/solr/apache-tomcat-5.5.28/common/lib/commons-math3-3.0.jar 50 -> /home/user/solr/apache-tomcat-5.5.28/server/lib/catalina.jar 51 -> /home/user/solr/apache-tomcat-5.5.28/server/lib/tomcat-http.jar 53 -> /home/user/solr/apache-tomcat-5.5.28/server/lib/tomcat-coyote.jar ...

Besides the list of jars used by the application, you also get the location of catalina.out, which is the place where Solr by default logs all it outputs.