Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (540)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (603)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Simple High Compression Java Game/Program Installer  (Read 6231 times)
0 Members and 1 Guest are viewing this topic.
Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Posted 2008-09-07 08:50:41 »

I have recently revisited an earlier project of mine which embedded a compressed version of an executable JAR into a "stub" loader JAR which decompressed the embedded JAR at runtime giving the same functionality of the original JAR.

I updated it to use LZMA compression and to use pack200. This made a significant impact on JAR size!

As a logical extension to this tool I have created an Installer tool ( LzInstaller ) which when given an input zip file containing the project to create the installer for, will iterate over all files in the zip file adding to an internal data file. If a encounted file is a JAR it will re-pack it with pack200. Once the data file is created, it is added to a JAR with a "stub" installer loader. This installer JAR is then compressed using the LZMA embedded JAR tool mentioned earlier to give fantastic results! Smiley

The latest version of the Embedded JAR tool (lzEmbedder) can be found here.

The latest version of the Installer tool (lzInstaller) can be found here.

The source code for both tools can be found here.

Feel free to use the code / tool in any way you like Smiley

To use high compression options you will need to increase the maximum heap size. Heap size during decompression is not effected greatly by compression option so you should not need to increase heap size when running the output JAR


An example of the performance of the tool:

Lobo - Java Web Browser (website)

uncompressed - 11.83 MB
official installer - 7.93 MB
zip file - 7.26 MB (7-zip Ultra compression option )
lzInstall version -1.84 MB



-updated links to recent versions.


Java4k RIP 2014
Offline zammbi

JGO Coder


Medals: 4



« Reply #1 - Posted 2008-09-07 09:29:03 »

Cool, so does this works fine for applets and/or jars needing external jars to run?

Current project - Rename and Sort
Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Reply #2 - Posted 2008-09-07 09:40:37 »

at the moment the embedded JAR tool will only work for self-executing JARs (or JARs to be launched via Webstart with full permissions) applets would probably never work due to the funky stuff i have to do with the default class loader.

The compressed JAR "should" work fine with external JARs. I will have to run a test to see Smiley

Java4k RIP 2014
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Reply #3 - Posted 2008-09-07 12:20:17 »

Hmm was not a simple as one might expect... but it is now able to use needed external JARs.

I assumed that the path entered via the command line -cp command will be added to the class path system properties... like wise i assumed that the path to the jar file which is being launched will be added to the class path... both were not the case and had to explicity added when searching for required external JARs...

Java4k RIP 2014
Offline zammbi

JGO Coder


Medals: 4



« Reply #4 - Posted 2008-09-07 12:43:14 »

Great, I will surely use this in the future.

Current project - Rename and Sort
Offline hishadow

Senior Newbie





« Reply #5 - Posted 2008-12-09 02:01:33 »

Is it possible to make decompression and linking usable within a signed applet? I'm currently at 5MB ultra-zipped, but with LZMA it gets down to 2.5MB.
Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Reply #6 - Posted 2008-12-09 02:29:34 »

I am not entirely sure... i am not very familiar with Applets. have you tried signing the resultant JAR?


Java4k RIP 2014
Offline hishadow

Senior Newbie





« Reply #7 - Posted 2008-12-09 03:18:36 »

Java can't read the LZMA compressed jar. I was thinking of something along the line:
main jar -> applet + lzma decompressor + lzma-packed jars -> decompress and load jars -> run as normal
Offline bienator

Senior Devvie




OutOfCoffeeException


« Reply #8 - Posted 2008-12-09 07:23:25 »

how much gain do we get with your approach compared to pure pack200 compression?

Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Reply #9 - Posted 2008-12-09 08:31:35 »

Java can't read the LZMA compressed jar. I was thinking of something along the line:
main jar -> applet + lzma decompressor + lzma-packed jars -> decompress and load jars -> run as normal

Just to be clear, you want to have an applet which will be able to read in lzma compressed pack 200 modified JAR files and launch them? That should not be that difficult do... you can modify the source code of the existing tool if you like Smiley

you will need to make it not look for a manifest in the JAR... rather you will need to somehow know what class to run as an applet from the JAR.

Unfortunately i do not have the time to look into making the tool work for applets Sad


Java4k RIP 2014
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Reply #10 - Posted 2008-12-09 08:33:03 »

how much gain do we get with your approach compared to pure pack200 compression?

if you mean if compared to pack200 + gz then i estimate between 20%-35% on average.

Java4k RIP 2014
Offline hishadow

Senior Newbie





« Reply #11 - Posted 2008-12-09 14:10:31 »

I couldn't find any java files in the sources jar.

How do you load the jar content? Do you use a custom ClassLoader?

ed: stupid me, trying to load a 7z file with the lzma decoder. Smiley
Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Reply #12 - Posted 2008-12-09 20:07:16 »

hehe Smiley

all you need to do is to install the lzinstaller and the source code is installed as well.

Java4k RIP 2014
Offline bobjob

JGO Knight


Medals: 10
Projects: 4


David Aaron Muhar


« Reply #13 - Posted 2008-12-11 20:16:05 »

I gave it a shot, and tried to use the installer on a 14 meg file

this is the error i got
Quote
DONE!
Adding to Data File: lzInstallerDeploy/LzInstallerDeploy.class
Adding to Data File: lzInstallerDeploy/UnPack200.class
Adding to Data File: META-INF/MANIFEST.MF
Adding to Data File: lzInstallerDeploy/ExtendedByteArrayInputStream.class
Adding to Data File: lzInstallerDeploy/ProgressWindow.class
Adding to Data File: lzInstallerDeploy/ReadListener.class
Adding to Data File: lzInstallerDeploy/CountingInputStream.class
Adding to Data File: lzInstallerDeploy/data/compressed.data
Compressing DataFile...
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
   at java.util.Arrays.copyOf(Unknown Source)
   at java.io.ByteArrayOutputStream.write(Unknown Source)
   at java.io.ByteArrayOutputStream.writeTo(Unknown Source)
   at com.sun.java.util.jar.pack.Package$File.writeTo(Unknown Source)
   at com.sun.java.util.jar.pack.PackageWriter.writeFiles(Unknown Source)
   at com.sun.java.util.jar.pack.PackageWriter.write(Unknown Source)
   at com.sun.java.util.jar.pack.PackerImpl$DoPack.flushPackage(Unknown Source)
   at com.sun.java.util.jar.pack.PackerImpl$DoPack.flushAll(Unknown Source)
   at com.sun.java.util.jar.pack.PackerImpl$DoPack.run(Unknown Source)
   at com.sun.java.util.jar.pack.PackerImpl.pack(Unknown Source)
   at lzEmbedder.Pack200.pack(Pack200.java:66)
   at lzEmbedder.LzJAREmbedder.convertToLZMA(LzJAREmbedder.java:261)
   at lzEmbedder.LzJAREmbedder.embed(LzJAREmbedder.java:144)
   at lzInstallerCreator.LzInstaller.main(LzInstaller.java:284)


My Projects
Games, Webcam chat, Video screencast, PDF tools.

Javagaming.org with chat room
Offline zammbi

JGO Coder


Medals: 4



« Reply #14 - Posted 2008-12-11 20:19:44 »

Sounds like you just need to increase the Java heap space bobjob.

Current project - Rename and Sort
Offline moogie

JGO Ninja


Medals: 15
Projects: 6
Exp: 10 years


Java games rock!


« Reply #15 - Posted 2008-12-12 10:55:52 »

yep either increase your heap size eg -Xmx256M  or select a lower level of compression

Java4k RIP 2014
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Mr.CodeIt (24 views)
2014-12-23 03:34:11

rwatson462 (53 views)
2014-12-15 09:26:44

Mr.CodeIt (45 views)
2014-12-14 19:50:38

BurntPizza (85 views)
2014-12-09 22:41:13

BurntPizza (110 views)
2014-12-08 04:46:31

JscottyBieshaar (79 views)
2014-12-05 12:39:02

SHC (89 views)
2014-12-03 16:27:13

CopyableCougar4 (96 views)
2014-11-29 21:32:03

toopeicgaming1999 (155 views)
2014-11-26 15:22:04

toopeicgaming1999 (152 views)
2014-11-26 15:20:36
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!