Easy shrink method

I want to contribute to the current 4K contest.

My jar is 6.819 Bytes big. I am doing this at the moment with little success:

[quote]pack200 --repack fourK.jar
pack200 fourK.jar.pack.gz fourK.jar
The result is 4.420 Bytes.

All the shrinking tools seem to be offline :frowning:

Please help me, thanks guys :slight_smile:

Try JShrink.

I already tried to download it, but the download link is broken


use evaluation (the link work):


Or proguard :

Or both if you need !

Thanks for your help :smiley:

It worked out very well :smiley:
First I used Jshrinker, than pack200. Now I got a shrink.pack.gz file. How do I test my applet if it still works?


I use the method described here:

Using all those steps on my jar, I reduce the final output from 6.962 bytes to 3.860 bytes.

To test a pack200ed jar you have to setup a webserver and use the packEnabled parameter.

<applet code="A.class" archive="game.pack.gz" width="495" height="450" >
< param name="java_arguments" value="-Djnlp.packEnabled=true" />

I tried it your way, but I get errors after the 3rd step with the jarg.jar.

But the jshrinker does the job anyway, but I it won’t run in the browser, although I added the params to the applet tag. It says no G.class found… :frowning:

Whats wrong there?

My steps

<object type="application/x-java-applet" height="600" width="800">
	  <param name="code" value="G.class" />
	  <param name="archive" value="game.pack.gz" />
	  <param name="java_arguments" value="-Djnlp.packEnabled=true"/>
	  Applet failed to run.  No Java plug-in was found.

Did you try your packed applet on a distant webserver ?

reducing the target to 1.5 will save you 300-400 bytes in final jar.

I’ll do some self-promoting here for this. I have collected the different techniques at shrinking my game jars down into a Mercurial project, which can be downloaded here:

hg clone http://groboutils.hg.sourceforge.net:8000/hgroot/groboutils/java4k

There’s a readme file that will (hopefully) walk you through the setup steps.

Yes I tried, and still ClassNotFoundException. I tried letting the Jshrink step out. Still not better. The applet cannot be started trough the webbrowser.

Thanks for that :slight_smile: helped a bit

I only used pack200 with the following options:

That worked for me, now the packed “Fuego” has approx 3.700 instead of 4200 bytes…

Kronos, can you report accurately all the errors you get on or after the 3rd step described by SimonH ?

Even better, report also here everything you type on the command line.

Actually, you did it…

Use Proguard+Pack200, I get 40k files down to 4k

I’m getting desperate :frowning:

I only used eclipse export, than pack200 with mentioned options:


and this HTML5 object Tag:

	<object type="application/x-java-applet" height="600" width="800">
	  <param name="code" value="G.class" />
	  <param name="archive" value="jar/game.pack.gz" />
	  <param name="java_arguments" value="-Djnlp.packEnabled=true"/>

also with cache_archive. I’ve seen this several times.

Please help me :slight_smile: I want to submit today :o

P.S.: the applet without pack200’ing it, runs very well in the browser with the object tag.

you did read what I said that you have to set it up in a real webserver ?
You cannot simply create a .html page with this code and double click it. It will not work .

In any case, just submit it and keep trying to set it up on your computer. The approval process takes 1 or 2 days anyway, and by then you’ll know if it works or not.

I myself submitted my pack200ed without testing it. If the pure jar works in your machine, pretty much likely it will run pack200 in the java4k site.

Here is the applet-html-snippet from my entry on java4k, maybe that helps?

<applet code="Fuego.class" archive="fuego.pack.gz" width="800" height="600">
   <param name="java_arguments" value="-Djnlp.packEnabled=true" />

I uploaded it on my website, and nothing happened. I hope the guys from 4K know better to handle that thing :smiley: I really hope :wink:

Thank you all for your patience :wink:

I updated the my Java4k tools to include a trivial HTTPD server that knows how to handle pack200 file requests.

If you want to play along without downloading the whole package and getting it running, here’s the simple guide:

  1. Download the source from here: http://groboutils.hg.sourceforge.net/hgweb/groboutils/java4k/raw-file/28651c630d4f/tools/src/net/sf/groboutils/java4k/httpd/NanoHTTPD.java
  2. (optional) Remove the package line to make the simple guide easier.
  3. Compile NanoHTTPD.java
  4. Put a simple html file named “index.html” and your pack200 compressed applet (named *.jar.pack.gz) in an empty directory. For the html page, something simple like this works (replace the attributes in caps with the actual value; notice that the archive name ends in “.jar”):

<html><body><applet ARCHIVE="x.jar" CODE="M.class" WIDTH="200" HEIGHT="400">

  1. Run the NanoHTTPD class like: “java -cp . NanoHTTPD -p 8080 -d (directory of html and pack.gz file)”
  2. Point your web browser to “http://localhost:8080/

Kronos, did you try to unpack and test locally the resulting jar in a standard applet code ?

Input file : game.pack
Command line>unpack200 game.pack game.pack.test.jar  
Output file : game.pack.test.jar