Reputation: 302
I compressed my library jar files using 7-zip with ultra compression for smaller size. But after that when i use it in Netbeans my Swing app doesn't show my library jar loaded. Java cannot access the content inside the library jar file.
Does 7-zip compression wont support in Java? Any methods or remedies to solve this issue?
Any other compression tool for java to compress the jar files to smaller size?
My jar file1 size is 13mb and my client feels that it is a heavy weight to load and he wants that to be a very small size. With pack200 I got the jar size to 4.5mb (which was good). But ended up with error loaded into main jar file.
Upvotes: 0
Views: 759
Reputation: 168825
Zip them using either 'standard compression', or by using pack200 - the only two compression formats understood by the JVM. The Jar tool is of course, excellent for that purpose. I would generally call it from an Ant build script.
One excellent way to reduce the size of the classes of a distributable is to obfuscate the code. While ultimately ineffective at providing the 'code protection' for which they are generally used, obfuscation will typically make the binaries significantly (40%-60%) smaller.
the library file for my app.. it has dj native swing and other classes like ppt reader etc...
Give obfuscation and standard compression a try. Report back the size and success/failure to load & verify.
Since it is apparently a desk-top app., also consider splitting the app. into separate Jars and delivering them lazily using Java Web Start. That means they are only loaded when needed. E.G. the PPT reader might be for the help system. It is not necessary to load the help for the app. to get on-screen, only if they hit F1
With lazy loading, the PPT reader and help files would only be downloaded when the user requested help, and then with a progress dialog.
Even better, if an API gets an update, simply load the updated Jar to the server and JWS will automatically update the version on the client (if required - e.g. it would not update any 'lazy' Jars that have not already been cached).
Upvotes: 3
Reputation: 718788
Does 7-zip compression wont support in java
That is correct. Java cannot handle a JAR file that has been compressed by some 3rd party tool.
The simplest option is to not do this. (Get rid of some of those movies or whatever that are using all of your disc :-) )
The next simplest option is to use the 7-zip tool to uncompress the file before you attempt to use it in Java.
Finally, if you are simply attempting to execute your app using this super-compressed JAR file, then you could write a class loader that used 7-zip to uncompressed the JAR file on the fly. (Or if the algorithm that 7-zip uses is published, you could implement an uncompressor in Java and embed that in your class loader.)
Upvotes: 1
Reputation: 500317
A .jar
file has to be compressed using the jar
tool. The format itself is essentially zip
with some Java-specific metadata.
I don't think the standard classloader supports other compression formats.
Upvotes: 1