Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (511)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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  
  How to BUILD a 4K game.  (Read 4599 times)
0 Members and 1 Guest are viewing this topic.
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Posted 2005-12-15 03:13:39 »

I thought it might be helpful to people who have never used Ant before to show a build script that can make shrinking your jar much easier.  With the click of a button, you can compile, obfuscate, unzip and rezip from an Ant build file.  This will also make it easier to experiment better with each option.
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  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
<project name="Asteroids4k" default="compile" basedir=".">
    <taskdef resource="proguard/ant/task.properties" classpath="C:/Apps/Programming/Java/proguard3.4/lib/proguard.jar" />
    <taskdef name="jarg" classname="jarg.JargTask" classpath="C:/Apps/Programming/Java/jarg/jarg.jar" />

    <description>
        Ant build script for Asteroids, Java 4K entry
    </description>

    <!-- Global properties for this script -->
    <property environment="env" />
    <property name="j4k.root" location="${basedir}" />
    <property name="j4k.src" location="${j4k.root}/src" />
    <property name="j4k.bin" location="${j4k.root}/bin" />
    <property name="j4k.dist" location="${j4k.root}/dist" />

    <target name="init">
        <echo>${ant.version}</echo>
        <!-- Creates a time stamp -->
        <tstamp>
            <format property="timestamp" pattern="yyyyMMddHHmmss" />
        </tstamp>
        <!-- Create the classes directory structure -->
        <mkdir dir="${j4k.bin}" />
        <mkdir dir="${j4k.dist}" />
    </target>

    <target name="compile" depends="init" description="compiles all source files">
        <!-- Compile the java code from ${j4k.src} into ${bin} -->
        <javac destdir="${j4k.bin}" debug="off" deprecation="off">
            <src path="${j4k.src}" />
            <include name="**/*.java" />
        </javac>
    </target>

    <target name="recompile" depends="clean, compile" description="rebuilds the project" />

    <target name="clean" description="deletes classes and archive directories">
        <!-- Delete the output directory trees -->
        <delete dir="${j4k.bin}" />
        <delete dir="${j4k.dist}" />
    </target>

    <target name="build" depends="_rezip" description="deletes classes and archive directories">
    </target>

    <target name="build_2" depends="_obfuscate" description="deletes classes and archive directories">
    </target>

    <target name="rebuild" depends="clean, build" description="rebuilds the project" />

    <target name="_package_jar" depends="compile" description="generate the jar file">
        <zip destfile="${j4k.dist}/Asteroids4Kpre.jar" compress="yes">
            <fileset dir="${j4k.bin}">
                <include name="*.*" />
                <include name="*" />
            </fileset>
        </zip>
    </target>

    <target name="_re_package_jar" depends="clean, _package_jar" description="generate the jar file">
        <zip destfile="${j4k.dist}/Asteroids4Kpre.jar">
            <fileset dir="${j4k.bin}">
                <include name="*.*" />
                <include name="*" />
            </fileset>
        </zip>
    </target>

    <target name="_obfuscate" depends="_rezip" description="obfuscate/compress classes">
        <proguard verbose="true">
         -keep public class A {
            public static void main(java.lang.String[]);
         }
         <injar path="${j4k.dist}/Asteroids4Kpre.jar" />
            <outjar path="${j4k.dist}/Asteroids4K.jar" />
            <libraryjar path="C:/Apps/Programming/Java/j2sdk1.4.2_10/jre/lib/rt.jar" />
        </proguard>
    </target>

    <target name="_obfuscate_2" depends="_package_jar" description="obfuscate/compress classes">
        <jarg jarfile="${j4k.dist}/Asteroids4Kpre.jar" verbose="true" rnlog="rnlog.txt" />
    </target>

    <target name="_unzip" depends="_obfuscate_2" description="obfuscate/compress classes">
        <unzip src="${j4k.dist}/Asteroids4Kpre_s.jar" dest="${j4k.dist}" />
    </target>

    <target name="_rezip" depends="_unzip" description="obfuscate/compress classes" >
        <exec executable="7z" output="error.log" dir="${j4k.dist}">
            <arg value="a" />
            <arg value="Asteroids.jar" />
            <arg value="A.class" />
        </exec>
    </target>
</project>

Offline Alan_W

JGO Knight


Medals: 8
Projects: 3


Java tames rock!


« Reply #1 - Posted 2005-12-15 06:33:52 »

Very useful.  I've been meaning to get to grip with ant for some time, but have to confess to using .bat files.  Does "output=error.log" put the output in a file or in the compilation message window.  It would be nice to display the final size of the compressed jar.  If necessary I could write a small java program to determine the file size & write the output, which somehow needs to end up in the compilation message window, rather than on the console.

Alan

Time flies like a bird. Fruit flies like a banana.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 816
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2005-12-15 08:26:21 »

Everytimes I see XML used in a way it wasn't meant to be, I get the shivers.

I too make a batch-file to compile, zip and show the final file-size. I can hardly believe Ant makes that easier.


(not that I ever used Ant, scripting in XML scares the crap out of me)

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline CaptainJester

JGO Knight


Medals: 12
Projects: 2
Exp: 14 years


Make it work; make it better.


« Reply #3 - Posted 2005-12-15 10:51:08 »

Does "output=error.log" put the output in a file or in the compilation message window.

That was my attempt to get 7-Zip to output something useful.  It doesn't work yet.  Still trying to figure out how to get it to display a message.

Online kevglass

JGO Kernel


Medals: 188
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #4 - Posted 2005-12-15 10:53:57 »

Quote
Everytimes I see XML used in a way it wasn't meant to be, I get the shivers.

I too make a batch-file to compile, zip and show the final file-size. I can hardly believe Ant makes that easier.


(not that I ever used Ant, scripting in XML scares the crap out of me)

Aye, I'm still very much this way. XML and scripting doesn't make sense in my head (though the BPEL standard seems to be proving otherwise). However, where ANT is concerned I'll make an exception. There is something wonderful about having a script that does everything for me and is integrated into my IDE. Click Button -> Package in My Bespoke and Convoluted Way.

My script to build, package, sign and upload the appropriate jars to webstart website has saved me tonnes of time on this last project.

Kev

Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #5 - Posted 2005-12-15 12:56:41 »

(not that I ever used Ant, scripting in XML scares the crap out of me)

That's just because everyone always show complex ANT scripts. A basic ANT script is easy to write and pick up. I used to use nothing but batch scripts myself, right up until I started noticing that every program that had an ANT script was easy to build. Considering that batch/shell scripts tended to be environment dependent, I found myself wishing that more programmers used ANT (even though I was avoiding it). Finally, I bit the bullet and realized that it's actually very easy, and is a good way to handle complex builds. Smiley

See if you can figure out this script. The section named "compile", for example, simply calls JavaC, then copies the final files to other directories.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Anon666

Junior Duke




aka Abuse/AbU5e/TehJumpingJawa


« Reply #6 - Posted 2005-12-15 19:57:05 »

Takes a while to master their use, but used in conjunction with eclipse - ant scripts are truely fantastic!
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #7 - Posted 2005-12-15 20:26:20 »

Takes a while to master their use, but used in conjunction with eclipse netbeans - ant scripts are truely fantastic!

Netbeans has always been ahead on ANT support. Wink

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Anon666

Junior Duke




aka Abuse/AbU5e/TehJumpingJawa


« Reply #8 - Posted 2005-12-15 22:22:38 »

Takes a while to master their use, but used in conjunction with eclipse netbeans - ant scripts are truely fantastic!

Netbeans has always been ahead on ANT support. Wink

realy?? what does netbeans do that eclipse doesn't?
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #9 - Posted 2005-12-15 22:47:25 »

realy?? what does netbeans do that eclipse doesn't?

The entire build system is now ANT. If you create a new project, Netbeans creates ANT scripts behind the scenes that it uses to store all its project data. Those scripts can then be taken to any other IDE and reused. If you already have a handcrafted script (my preference), Netbeans will import all the settings from the file and work directly from that build file for your project.

It's nice.  Grin

Java Game Console Project
Last Journal Entry: 12/17/04
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Honk

Junior Newbie





« Reply #10 - Posted 2005-12-15 23:12:48 »

Those scripts can then be taken to any other IDE and reused. If you already have a handcrafted script (my preference), Netbeans will import all the settings from the file and work directly from that build file for your project.
eclipse can do the same.. yay Smiley
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #11 - Posted 2005-12-16 03:40:07 »

eclipse can do the same.. yay Smiley

At least the last time I checked, Eclipse's project system wasn't based entirely around ANT. It has ANT support, yes, but that's not the same thing. Also, Netbeans has autocomplete for ANT files, and can integrate with the ANT documentation via a plugin from the Update Center. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline swpalmer

JGO Coder


Exp: 12 years


Where's the Kaboom?


« Reply #12 - Posted 2005-12-16 04:24:57 »

I like that Netbeans has Ant as the "project" file.  But that said, it is a poor system to use during development compared to Eclipse.  It is just so much slower to run an Ant script to to a build, run an Ant script to start debugging, etc..

Eclipse's method of compiling each class instantly when you save the file (with no perceivable delay) make my work flow go much faster.  There is basically no compile step ever while doing general work, the .class files are just always there and up to date.  That's sweet.

Then I looked at the Ant build files used by Netbeans... sort of icky.. I see what they are doing, trying to abstract everything out and stick in hooks all over the place.. basically to overcome what would otherwise be a sort of limited project file.  It gets the job done, that's cool.  And it is nice to have an Ant script that is updated automatically with the project.  If only it didn't slow me down.  I use Eclipse and it's built in compiling, along side my own hand made Ant file for "production" builds.

If Netbeans went for a hybrid approach where they had an integrated compiler like Eclipse,  didn't use Ant to do EVERYTHING, like launch the debugger... yet kept and maintained the Ant file as well..  that would be great.

In terms of a 4k game where you generally only have a single source file.. Ant is overkill.  A batch file is way smaller, simpler, and easier to deal with.

Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #13 - Posted 2005-12-16 13:25:10 »

I like that Netbeans has Ant as the "project" file.  But that said, it is a poor system to use during development compared to Eclipse.  It is just so much slower to run an Ant script to to a build, run an Ant script to start debugging, etc..

The big thing is to not run a cleaning before you run the compile. A lot of developers make this mistake because they got an ANT file with the cleaning built into the full build process.

Quote
Eclipse's method of compiling each class instantly when you save the file (with no perceivable delay) make my work flow go much faster.  There is basically no compile step ever while doing general work, the .class files are just always there and up to date.  That's sweet.

Indeed. A lot of developers swear up and down by this. My only issue with it is that it can encourage developers to work from a "dirty" build. The next time a full compile is run, nothing builds because the files were all out of date. (I've been biten by this from Eclipse users a few times.) Thankfully, a good build process can make up for this problem. Smiley

Quote
In terms of a 4k game where you generally only have a single source file.. Ant is overkill.  A batch file is way smaller, simpler, and easier to deal with.

Agreed. I use Unix shell scripts for every stage of the build. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline Honk

Junior Newbie





« Reply #14 - Posted 2005-12-16 13:47:48 »

Who cares if eclipse is not built around ant? You can create ant files from your project and you can create projects from ant files. What else do you need? Smiley
Offline Malohkan

Senior Duke




while (true) System.out.println("WOO!!!!");


« Reply #15 - Posted 2005-12-18 05:55:02 »

Agreed, I don't see a reason why you would want your system built on it if it already fully supports it.  At least in my experience with Ant in working on the JRPG, running a project or building it with Ant seemed clunky and slow.  Doing a regular eclipse build and eclipse run without getting Ant involved is nicer in my opinion.

Admin and Game Developer at
GameLizard.com
Play Rimscape!    |    Play Conquer!
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (42 views)
2014-10-16 15:22:06

Norakomi (32 views)
2014-10-16 15:20:20

lcass (37 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (66 views)
2014-10-14 00:35:47

TehJavaDev (59 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (85 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!