advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Download the code for this article
Partners & Affiliates
advertisement
advertisement
advertisement
Average Rating: 4.7/5 | Rate this item | 3 users have rated this item.
 

Minimize Java Distributions with an Automated, Custom JAR File

Larger applications frequently get loaded down with a heavy burden of unused library files. Learn to create a custom classloader that automatically builds a JAR file that contains only the classes you need. 


advertisement
his article presents a solution to a problem that you might not have known you had—the size of your Java code.

Java programs can run the gamut from very small to very large. In fact, the variance is much larger in Java than in any other language. This is partly because the Java runtime (JRE) contains a great deal of library code that doesn't need to be included in an application, allowing applications to be smaller than they otherwise would.



However, if you've ever worked on a suite of Java programs—especially one that used a set of evolving libraries—you know that Java programs can grow extremely large. Java encourages modular design and code reuse, and it's not uncommon to find yourself including code you've never seen before into a bundled application, simply because it's part of your company's library set.

In such cases, you might be tempted to remove some of the dead code, but this isn't something you want to do by hand, and the larger and more complex the program, the more reluctant you should be to attempt this.

Classloader to the Rescue
Fortunately, Java provides a solution. You can use the power of Java Classloaders to track the code that your application uses. More specifically, you can get a very precise idea of which classes you are using and which you aren't.

In this article, I'll develop a utility that will run a program under a monitor. This monitor will track the classes that are loaded, and when the program is done, it will create a JAR file containing only the classes you need. I call this program 'JarMaker.' Along the way, you'll learn a lot about the Java Classloader. I'll start there, with the basics of the Java Classloader.

  Next Page: The Classloader Concept


Page 1: IntroductionPage 3: A Note About ClassLoaders
Page 2: The Classloader ConceptPage 4: Calling the Classloader
Please rate this item (5=best)
 1  2  3  4  5
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs