moogie
|
 |
«
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  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!
|
|
|
|
|
Markus_Persson
|
 |
«
Reply #1 - Posted
2006-12-08 09:56:06 » |
|
Sweet, thanks. =D
|
|
|
|
zeroone
|
 |
«
Reply #2 - Posted
2006-12-08 15:51:10 » |
|
Cool.
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
x30ice
Senior Newbie 
|
 |
«
Reply #3 - Posted
2006-12-08 16:08:28 » |
|
Great! Lots of thanks.
|
|
|
|
|
|
|
moogie
|
 |
«
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
|
|
|
|
|
CaptainJester
|
 |
«
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.
|
|
|
|
moogie
|
 |
«
Reply #7 - Posted
2006-12-09 10:57:41 » |
|
no problems 
|
|
|
|
|
appel
|
 |
«
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  Of course this depends on the the code, might not work for others.
|
|
|
|
moogie
|
 |
«
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  edit: From the JShrink website: 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  but I will attempt to get it to work!
|
|
|
|
|
Games published by our own members! Check 'em out!
|
|
oNyx
|
 |
«
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
|
|
|
|
moogie
|
 |
«
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.
|
|
|
|
|
moogie
|
 |
«
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?
|
|
|
|
|
oNyx
|
 |
«
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.
|
|
|
|
moogie
|
 |
«
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?
|
|
|
|
|
oNyx
|
 |
«
Reply #15 - Posted
2006-12-12 00:34:26 » |
|
|
|
|
|
moogie
|
 |
«
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  hmm there is no stack trace or error message...
|
|
|
|
|
oNyx
|
 |
«
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
|
|
|
|
moogie
|
 |
«
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.
|
|
|
|
|
oNyx
|
 |
«
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.
|
|
|
|
moogie
|
 |
«
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?
|
|
|
|
|
appel
|
 |
«
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> |
|
|
|
|
moogie
|
 |
«
Reply #22 - Posted
2006-12-18 00:16:40 » |
|
This is good (in a way  ) 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? )
|
|
|
|
|
moogie
|
 |
«
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:
|
|
|
|
|
appel
|
 |
«
Reply #24 - Posted
2006-12-20 10:24:10 » |
|
Pretty impressive  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.
|
|
|
|
appel
|
 |
«
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
|
|
|
|
moogie
|
 |
«
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?
|
|
|
|
|
appel
|
 |
«
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. 
|
|
|
|
moogie
|
 |
«
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.
|
|
|
|
|
moogie
|
 |
«
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.
|
|
|
|
|
|