• Home
KodEduKodEdu
  • Home

How to Remove Unnecessary Jars!

  • Posted by Rahman Usta
  • Categories Genel, Uncategorized, Yazılar
  • Date 19 June 2013

Your application may turn into Jar garbage maybe not in small projects but in projects which has an increasing diameter more and more. I’m sure once upon a time you thought to have an application and then remove the unnecessary Jars with it.

We use Jar libraries in our projects sometimes for a need and sometimes for developing software easily. One of the biggest reasons of why projects turn into Jar garbage may result from not knowing which library serves for what. Thus, due to the dependencies we include Jar libraries in projects, explicitly whatever we find, because of not getting compile and runtime exceptions.

For this purpose, I want to introduce you an excellent software tool to detect unused Jars.

 

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.

A sample output:

  • Share:
author avatar
Rahman Usta
Java Champion, Java* Trainer and Author. JCP Expert, Istanbul JUG and Adopt a JSR member. Duke's Choice Award 2015 winner. Ex-Voxxed Istanbul Organizer. Creator of AsciidocFX.

Previous post

Java API for JSON Processing – Creating JSON Objects
19 June 2013

Next post

Jax-RS 2 and LongPolling based Chat Application
25 June 2013

You may also like

collector
Distributed Map-Reduce Model using Java 8 and Java EE 7 WebSocket
16 November, 2014
server-sent-events-jax-rs-2
HTML 5 Server Sent Events on Glassfish 4
27 November, 2013
concurrency
Java EE 7 – Concurrency Utilities
23 October, 2013

    2 Comments

  1. Sivapsr psr
    6 April 2018
    Reply

    Hai @Rahman Usta,

    Am download loosejar and paste working directory.

    Unable to execute command properly. When I try to execute below command :
    C:\Program Files (x86)\myApp>java -javaagent:loosejar-1.1.0.jar com.my.testapp.Main -cp com.my.testapp.Main

    Error: Could not find or load main class Main
    My main class name is com.my.testapp.Main and my jar name is com.my.testapp.Main

    • Rahman Usta
      10 June 2018
      Reply

      Add your own class/jars to classpath.

Leave A Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • TürkçeTürkçe

Gözde yazılar

Java EE 7 – Concurrency Utilities
23Oct2013
HTML 5 Server Sent Events on Glassfish 4
27Nov2013
Distributed Map-Reduce Model using Java 8 and Java EE 7 WebSocket
16Nov2014
CDI – @Default and @Inject Annotations
14Jun2013

Recent Posts

  • First look at HTTP/2 Server Push in Java Servlet 4.0 Specification 26 April 2017
  • Distributed Map-Reduce Model using Java 8 and Java EE 7 WebSocket 16 November 2014
  • HTML 5 Server Sent Events on Glassfish 4 27 November 2013
  • Java EE 7 – Concurrency Utilities 23 October 2013
  • Combine JaxRS 2.0 Rest Client, Java FX 2, Spring MVC and Hibernate 15 August 2013

Get Java Software

React.js Eğitimi Başlıyor
11-22 Eylül, 2017
Eğitmen
Rahman Usta
İletişim

merhaba@kodedu.com

  • Hakkında
  • Gizlilik Politikası
  • İletişim
  • Referanslar
Kodedu Bilişim Danışmanlık
Cemil Meriç mah. Çelebi sok.
No:16/3 Ümraniye/İSTANBUL
Tel: 0850 885 38 65
Alemdağ V.D.: 8960484815

KODEDU © Tüm hakları saklıdır.