aspose file tools*
The moose likes Java in General and the fly likes Checking jar file contents are complete Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Checking jar file contents are complete" Watch "Checking jar file contents are complete" New topic
Author

Checking jar file contents are complete

Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Hi,

I've yet to hear anyone ask this question about a problem I used to have and finally wrote a program to solve.

[I}How do you insure that a jar file contains all the needed class files?
[/I]
I have several utility classes that exist on my CLASSPATH that I use to develop various programs I use. I acccess them via the CLASSPATH during a program development phase, and put them into a jar file with the classes for project I'm working on. I make a batch file with a jar command to build the jar file and usually forget to include some class which then causes the program to fail when I click on the jar file to start it. I'm working on a Win98 system. Because the default for "starting" a program in a jar file is javaw, you don't see any error messages. To find the problem, you open a DOS window and enter: java -jar <jarfilename> and then are able to see the error message about a missing class file.

Does anyone else have this problem? How do/did you solve it?

Norm
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

Actually, the solution is to not use a global CLASSPATH (as some of the rabid, foaming-at-the-mount anti-global-classpath zealots will soon be here to tell you!) Use Ant (or make, if you're a retro guy) and then use the same classpath in Ant to compile as you use in Ant to build your jar. Because the same list of classes are used for both, you can't make a mistake!


[Jess in Action][AskingGoodQuestions]
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
Thanks for the response. I'll have to get a copy of Ant and look at it.
A question about how Ant works:
For Ant to solve my problem it would have to keep track of which of my utility classes I use in a program I'mn writing and also what classes each of those utility classes use. It can then build a jar file with all and only the class files needed for the program to work.
If I have to manually enter which of my utility classes I'm using, I can just as easily create the batchfile with the jar commmand (and of course leave out some class in either case).

My utility classes are mostly in one package, say the same idea as java.util.*
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24168
    
  30

The approach I've outlined will create a complete jar, but not a minimal jar. Unless you're writing an applet (so that download size is important) people generally don't bother trying to do what you're asking about. They just include a library all of a piece.

But in any case, there are tools that will analyze a jar and remove unused classes. I know that commercial obfuscators like Dash-O Pro do this; I'm not sure if any of the equivalent open-source tools like Retroguard have this capability or not, but it's worth a look.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking jar file contents are complete
 
Similar Threads
Need help in javax.mail package.......very urgent
Import a non-packaged class??
Where are step by step servlet and JSP instructions?
import and package... ?
How do i find out the relative path for my jar?