Remove Unnecessary Jars!
Join the DZone community and get the full member experience.Join For Free
LooseJar LooseJar is software that discovers which Jar file is used how often through Java Instrumentation library. Instrumentation is a standard library which serves measurement process about code without affecting the ordinary operation of Java codes and allows obtaining a variety of information.
How to Run LooseJar? You have to define software as Java agent in your application’s JVM parameter. For example:
java -javaagent:<LooseJar Path> <Your ClassName> -cp <Your Jars>You can use Java agent as in the above syntax example. If your application is a web application, you can define Java agent at JVM settings of the default application server. Point to be considered here is testing points dependent to all libraries from running to termination of the application in order to obtain detection about which library is used how often. Unit tests and BDD tests can be used to measure the overall Looser application and Selenium tests can be used if web application is being used. For example you have a method named getSQLConnection(). This method requires sql connection and uses mysql connector driver in the background. If this method is not called when Looser agent is active, Looser agent provide you information about mysql dependency is not being used. This point must be considered in the use of Looser.
Conclusion So, how Looser will give us information about which Jar is used how much? There are two ways to obtain this information. Firstly, this information is provided as a console output immediately after the application is terminated. The second way is accessing with JMX connection in the run-time and accessing to summary() method of Looser as MBean method. JMX Jconsole or VisualVM can be used to access with JMX.
If your applications' result contains any 0.00% rated Jars, you can remove it from CLASSPATH.
Real content above, can be accessed at http://en.kodcu.com/2013/06/remove-unnecessary-jars/
Opinions expressed by DZone contributors are their own.