Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  4KJO (four Kilobyte game JAR optimiser)  (Read 14594 times)
0 Members and 1 Guest are viewing this topic.
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Posted 2006-12-08 04:58:53 »

My poorly made and non-robust utility is now at a reasonably stable level that people other than myself can probably use it Smiley

This Utility attempts to perform different combinations of java byte code optimisers and different permutations of settings for kzip and BWJFlate to attempt to shrink the total size of an input JAR.

I have experimented on most of the entries thus far and they all can be compressed more by the utility.

for example:

Squarius has a 100 byte saving compressing to 3,943 bytes
l4krits has a 244 byte saving compressing to 3,783 bytes
Goop has a 142 byte saving compressing to 3940 bytes

Note: all these tests were performed using the default settings. with testing the other settings I am sure more compression would be able to be achieved.

Note 2: This utiltiy only works on windows due the use of kzip.exe and bwjflate.exe


usage:

java -jar 4KJO 

will give you the command line options

java -jar 4KJO -gui

will open up a settings gui. I recommend using this to read the help file!

I do not have a webpage so the  file is located at:

http://www.filehosting.cc/file/15913/4KJO-zip.html <---- OLD VERSION

see http://www.java-gaming.org/forums/index.php?topic=15497.msg124708#msg124708 for new version.



I am hoping that this utility  will allow my entry to squeeze into the 4096 byte limit. Hopefully it will allow others the same!
Offline Markus_Persson

JGO Wizard


Medals: 14
Projects: 19


Mojang Specifications


« Reply #1 - Posted 2006-12-08 09:56:06 »

Sweet, thanks. =D

Play Minecraft!
Offline zeroone
« Reply #2 - Posted 2006-12-08 15:51:10 »

Cool.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline x30ice

Senior Newbie





« Reply #3 - Posted 2006-12-08 16:08:28 »

Great! Lots of thanks.
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #4 - Posted 2006-12-08 22:42:49 »

Do you want to give it a try with mine?  I tried it and got a ton of errors and then it didn't write the final file.

http://unlimited.woogley.net/hosted/vector.jar

All I did was ProGuard then 7zip.

Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #5 - Posted 2006-12-09 00:33:51 »

I had the same errors when i tried your jar.

I recompiled your class and then tried again and it worked without a hitch. It shaved 170 bytes off your jar. (see attached file)

What version of Java did you use to compile the class in? It may not be java 6 compatible...

When i recompiled the class I was using java 1.5.04

Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #6 - Posted 2006-12-09 05:23:44 »

Wow.  That's great.  Thanks.

I am using JDK v1.5.0_09-b03.

Next time I will try your program before I try my stuff.  That may have been the problem.

Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #7 - Posted 2006-12-09 10:57:41 »

no problems Smiley
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #8 - Posted 2006-12-11 05:56:54 »

Nice tool. Takes a while to go through all the "permutations".

I do it manually though, I got JShrink which is a superb tool.

My way is the following:
1. Shrink with JShrink
2. Run ProGuard (check "overload agressively", in obfuscation tab)
3. Run JoGa
4. Repeat step 2. and/or 3. as needed, I only had to do it once
5. Compress contents with bjwflate.exe
6. All done.

For my game, that did it. I ran the 4KJO tool for like 30 minutes, but it did not find any smaller compression method Smiley

Of course this depends on the the code, might not work for others.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #9 - Posted 2006-12-11 06:55:10 »

Yep, that is basically what I was doing before... manually trying all the different permutations. This utility simply auto mates it.

using the -saveOutputConfig switch it will save the best settings so that in subsequent runs you can simply add the

I will see if the evaluation version of JShrink will be able to be used in this tool. It may give better results Smiley

edit:

From the JShrink website:

Quote
Note: the evaluation version of Jshrink does not include the command line or script interface used for automating obfuscation builds.

hmm this could make it difficult Tongue but I will attempt to get it to work!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #10 - Posted 2006-12-11 15:06:20 »

Bombed with:
1  
2  
3  
4  
5  
6  
7  
8  
[...]
PROGUARD OPTIMIZER->JODE OPTIMIZER->JARG OPTIMIZER->JOGA OPTIMIZER->
current optimiser: JOGA OPTIMIZER
java.lang.NullPointerException
        at JoGaOptimizer.cleanUp(JoGaOptimizer.java:53)
        at Process.permutate(Process.java:697)
        at Process.run(Process.java:171)
        at FourKJO.main(FourKJO.java:57)

(defaults... first run)

Jar file:
http://kaioa.com/k/fuze.jar

弾幕 ☆ @mahonnaiseblog
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #11 - Posted 2006-12-11 22:08:28 »

hmm, it would seem that the JoGa optimiser had errors silently (due to the verbosity level) and so when it tried to delete temporary files, they did not exist... I will see what i can do.
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #12 - Posted 2006-12-11 23:39:50 »

Umm... can you confirm that It gives the same error? I run the utiltiy on the jar file you provided and there was no error.

It compressed to 4044 bytes using the default configuration.

Perhaps you accidentally interacted with the JoGa GUI?
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #13 - Posted 2006-12-12 00:05:37 »

Yes, it still gives me that error. However, the point at which that happens appears to be random (takes anything from a few seconds to some minutes).

And I didn't interact with the GUI at all. No keystrokes, no button presses and the mouse cursor stayed on the very same pixel all the time.

弾幕 ☆ @mahonnaiseblog
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #14 - Posted 2006-12-12 00:20:15 »

ok that is odd.

can you run the utility in verbose mode and pipe it into a file and then give me the output?
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #15 - Posted 2006-12-12 00:34:26 »

http://phpfi.com/183971

Then it bombed.

弾幕 ☆ @mahonnaiseblog
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #16 - Posted 2006-12-12 01:32:07 »

i am surprised... there should be alot of output on the err stream as JoGa complains alot Smiley

hmm there is no stack trace or error message...
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #17 - Posted 2006-12-12 02:13:54 »

Ye... I only used >foo.txt, which only redirects stdout.

With this line stderr gets redirected to stdout (which gets redirected to some file):
java -jar 4KJO.jar -verbosity 2 fuze.jar>foo.txt 2>&1

http://phpfi.com/183980

弾幕 ☆ @mahonnaiseblog
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #18 - Posted 2006-12-12 02:25:59 »

hmm... it looks like JoGa did have an error and so it tried to clean up, but since it's working directroy does not exist it generated another exception. I now am null checking on the clean up. replace the JOGAOptimizer.class in the 4KJO.jar with the one attached to this post.

I also suggest cleaning up any left over files, or perhaps make a new folder which contains the jar files and try it again.

Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #19 - Posted 2006-12-12 21:47:08 »

Seems to not crash anymore. However, there are exceptions like:

java.io.FileNotFoundException: null\JoGaDIR\fuze_JOGA.jar

Which looks sorta weird.

弾幕 ☆ @mahonnaiseblog
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #20 - Posted 2006-12-12 23:12:29 »

yeah, for some reason it seems to not be assigning the "input" jar which whould lead to those errors.

I cannot replicate the problem on my end which disturbs me.

Can someone else try the utiltiy on the jar oNyx supplied to see if there is something different about my local system?
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #21 - Posted 2006-12-17 01:25:53 »

It's not working, I get errors and then it shuts down.

1. I downloaded 4kjo and extracted it
2. Ran "java -jar 4kjo.jar -gui"
3. Saved the default config into "c.xml"
4. Copied "starship.jar" into the 4kjo directory
5. Ran "java -jar 4kjo.jar -config c.xml -output starship_final.jar starship.jar"

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
C:\Stuff\Download\4KJO>java -jar 4kjo.jar -gui
Cannot open configuration file default.xml, using default (hard-coded) values.

C:\Stuff\Download\4KJO>java -jar 4kjo.jar -config c.xml -output starship_final.jar starship.jar
Cannot open configuration file default.xml, using default (hard-coded) values.
Class: S HAS MAIN METHOD.

current optimiser: PROGUARD OPTIMIZER
ERROR OCCURED WHILE OPTIMISING... skipping to next permutation...
java.lang.Exception: JAR file Corrupt: missing main class or other classes
        at Process.optimize(Process.java:506)
        at Process.permutate(Process.java:692)
        at Process.run(Process.java:171)
        at FourKJO.main(FourKJO.java:57)
current optimiser: JOGA OPTIMIZER
java.lang.NullPointerException
        at JoGaOptimizer.cleanUp(JoGaOptimizer.java:53)
        at Process.permutate(Process.java:697)
        at Process.run(Process.java:171)
        at FourKJO.main(FourKJO.java:57)

C:\Stuff\Download\4KJO>

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #22 - Posted 2006-12-18 00:16:40 »

This is good (in a way Tongue ) It can only get more stable when solving these issues.

can you send me the starship.jar (budgetanime AT hotmail DOT COM) ?

It looks like proguard is having issues. (what version of java did you compile it with? did you try compiling to the 1.4 compatible? )
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #23 - Posted 2006-12-20 08:08:38 »

I took your starship4K.jar and ran it through the optimiser. It had no errors, however the JODE optimised a little too much and the mouse buttons were not registering, but removing the JODE optimiser from the list to try, 4KJO was able to get another 47 bytes.

The settings i used if you want to repeat are attached:
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #24 - Posted 2006-12-20 10:24:10 »

Pretty impressive Smiley

Sorry, I forgot to send you an unoptimized jar that caused that error. I'll try to send you both the jar file and the xml file when work is over.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #25 - Posted 2006-12-21 05:51:34 »

I tried to run that config, but got errors:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
C:\Stuff\Download\4KJO>java -jar 4KJO.jar -config bestConfigOut.xml.txt -output S2.jar S.jar
Cannot open configuration file default.xml, using default (hard-coded) values.
java.io.IOException: File: BJWFlate.exe already exists!
        at Process.copyExecutable(Process.java:710)
        at Process.run(Process.java:64)
        at FourKJO.main(FourKJO.java:57)
Class: S HAS MAIN METHOD.
current optimiser: JOGA OPTIMIZER
ERROR OCCURED WHILE OPTIMISING... stopping...
java.io.FileNotFoundException: null\JoGaDIR\S_JOGA.jar (The system cannot find the path specified)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(Unknown Source)
        at java.util.zip.ZipFile.<init>(Unknown Source)
        at Process.stillHasClasses(Process.java:564)
        at Process.optimize(Process.java:506)
        at Process.run(Process.java:189)
        at FourKJO.main(FourKJO.java:57)
java.io.FileNotFoundException: C:\Stuff\Download\4KJO\S.jar.BEST_OPT.jar (The system cannot find the file specified)
        at java.util.zip.ZipFile.open(Native Method)
        at java.util.zip.ZipFile.<init>(Unknown Source)
        at java.util.jar.JarFile.<init>(Unknown Source)
        at java.util.jar.JarFile.<init>(Unknown Source)
        at Process.pack200Unpack200(Process.java:482)
        at Process.run(Process.java:217)
        at FourKJO.main(FourKJO.java:57)

C:\Stuff\Download\4KJO>


jar file: http://www.stratzone.net/4k/S.jar

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #26 - Posted 2006-12-22 01:05:12 »

hmm. i ran this JAR though the 4KJO using the settings i have posted earlier and it worked fine...

based on the stack trace it seems that a File.getParent() is returning null...

i am not sure why that would be the case... could you try again but using a fully qualified file name and path to the input JAR?

i.e.

 4KJO>java -jar 4KJO.jar -config bestConfigOut.xml.txt -output C:\Stuff\Download\4KJO\S2.jar C:\Stuff\Download\4KJO\S.jar

Can any one let me know what would cause the file system to not know what the parent would be?
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #27 - Posted 2006-12-22 20:29:47 »

could you try again but using a fully qualified file name and path to the input JAR?

i.e.

 4KJO>java -jar 4KJO.jar -config bestConfigOut.xml.txt -output C:\Stuff\Download\4KJO\S2.jar C:\Stuff\Download\4KJO\S.jar

Seems to have worked. Smiley

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #28 - Posted 2006-12-22 22:53:13 »

good to hear.

That behavior of returning null is not what i would expect... i will have to see if i can get around it.
Offline moogie

JGO Knight


Medals: 12
Projects: 6
Exp: 10 years


Java games rock!


« Reply #29 - Posted 2006-12-27 13:22:01 »

Based on some ideas formed when making this utiltiy i now have a preliminary process which seems to give approximatly 50-100 extra bytes.

This is based on embedding a pack200 compressed version of the optimised jar file (i.e. one which has been through the 4KJO optimiser) onto the end of a "launcher" class file.

This launcher class reads the embedded pack200 compressed jar, converts it into a normal JAR, adds the normal JAR into a classloader and then calls the constructor of the "main" class.

Since there is some foolery with File and ClassLoader the resulting JAR will need to be signed, or be an executable JAR.

I have attached an executable version of "Starship Invaders" which has been compressed from 4093 bytes to 4,034 bytes.

I hope with further optimisations of the launch class I can increase the gain.

Pages: [1] 2
  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.

pw (18 views)
2014-07-24 01:59:36

Riven (17 views)
2014-07-23 21:16:32

Riven (14 views)
2014-07-23 21:07:15

Riven (17 views)
2014-07-23 20:56:16

ctomni231 (45 views)
2014-07-18 06:55:21

Zero Volt (40 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (51 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!