Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (521)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (589)
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  
  Webstart, jar and resources  (Read 4296 times)
0 Members and 1 Guest are viewing this topic.
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Posted 2008-01-30 10:54:33 »

My game is running fine but it is all in one big jar (beside libs).

May be, should i split the jar (1 for the code, 1 for sprites, 1 by music) ?
For music, should i put the MP3 inside a jar (then use ...getResource("audio/music.mp3")...) or should i use directly the files ( File("./audio/music.mp3"), i'm not sure if webstart allow to use something else than jar ) ?
Offline CommanderKeith
« Reply #1 - Posted 2008-01-30 11:14:55 »

You're right, you put it inside the jar and do getResource. WebStart won't let you write things to the disk unless you use the jnlp.jar sand-boxed functions. (java.util.Preferences methods still work though, thank goodness!).

Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #2 - Posted 2008-01-30 14:54:38 »

The advantage of splitting it up are faster download of updates. Eg if the code is 100kb, textures are 1mb, and sound are 2mb, then clients would only have to download 100kb (instead of 3.1mb) if they want to play it again and you fixed one small bug in the meantime.

File does not work with webstart (if you want to load something from jars in general). Use URLs (getResource) and streams (getResourceAsStream).

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #3 - Posted 2008-02-01 08:14:12 »

How do you deal with several jars ?
For now, i have made a project by jar (i'm using Netbean). May be there is a way to make several jars in one project ?
Offline CommanderKeith
« Reply #4 - Posted 2008-02-01 11:44:41 »

One way is to make it into two separate projects, then compile and build (jar) one, then go to the other project and import the jar from the first project and then build the other project.  Then you've got two separate jars. There's probably a better way to do it, but I don't know.  Maybe you could ask on the www.netbeans.org forums

Offline cylab

JGO Ninja


Medals: 55



« Reply #5 - Posted 2008-02-01 17:24:36 »

Go to the "Files" tab and navigate to your projects "src" folder. Move the directories for your resource out of the src folder to exclude them from the main jar, so you have for example the following folder structure:
1  
2  
3  
4  
5  
6  
+ <YourProject>
   + audio
   + nbproject
   + sprites
   + src
   (...)


Then open your build.xml file and add the following target:
1  
2  
3  
4  
5  
    <target name="-post-jar">
        <mkdir dir="${dist.dir}/lib"/>
        <jar destfile="${dist.dir}/lib/${ant.project.name}-audio.jar" basedir="audio"/>
        <jar destfile="${dist.dir}/lib/${ant.project.name}-sprites.jar" basedir="sprites"/>
    </target>


This will create two additional jars under dist ("<YourProject>-audio.jar" and "<YourProject>-sprites.jar") with the contents of your audio and sprites folder.

After that switch back to the "Projects" tab and open your projects properties. Add the "audio" and "sprites" folder to the run-time libraries under the "Run" tab in the "Libraries" category. This last step is required to let your app load from your resource <i>folders</i> when starting from within the IDE.

Clean and build the project.

To let NetBeans correctly create a JNLP file for Web Start, open the project properties, Go to the "Application->Web Start" category and check the "Enable Web Start" box. Now open the "Libraries" category and switch to the "Run" tab again. For the JNLP-File to include your resource jars they have to be referenced as run-time libraries, so add "<YourProject>-audio.jar" and "<YourProject>-sprites.jar" to the list, too.


Mathias - I Know What [you] Did Last Summer!
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #6 - Posted 2008-02-04 09:12:44 »

Ok thanks. It create the jars  Grin.

(I should really learn more about ant). How to i had those jar to the manifest ? (Class-Path: ...)
Offline cylab

JGO Ninja


Medals: 55



« Reply #7 - Posted 2008-02-04 09:28:39 »

Just add the jar locations comma separated relative to your executable jar:
1  
Class-Path: lib/<YourProject>-audio.jar lib/<YourProject>-sprites.jar

Mathias - I Know What [you] Did Last Summer!
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #8 - Posted 2008-02-04 15:26:03 »

Well, by modifying the manifest.mf in the project folder, i can launch the jar in command line. But when i launch in the IDE, it doesn't find the audio/texture... it is base on a ant script and not on the manifest...
Well it is getting far too complicated to only create 2 jar files.
Offline cylab

JGO Ninja


Medals: 55



« Reply #9 - Posted 2008-02-04 15:44:55 »

Did you include the "audio" and "sprites" folders to the runtime-libraries?

Mathias - I Know What [you] Did Last Summer!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cylab

JGO Ninja


Medals: 55



« Reply #10 - Posted 2008-02-04 16:03:31 »

Another option would be just to leave the "audio" and "sprites" folder under "src" and exclude them from the main-jar by adding ", audio, sprites" to the "Exclude From Jar File" option under the "Build->Packaging" category of your project's properties.

To generate the two additional jars again, the "-post-jar" target has to look like this:

1  
2  
3  
4  
5  
    <target name="-post-jar">
        <mkdir dir="${dist.dir}/lib"/>
        <jar destfile="${dist.dir}/lib/${ant.project.name}-audio.jar" basedir="${src.dir}/audio"/>
        <jar destfile="${dist.dir}/lib/${ant.project.name}-sprites.jar" basedir="${src.dir}/sprites"/>
    </target>



Mathias - I Know What [you] Did Last Summer!
Offline broumbroum

Junior Devvie





« Reply #11 - Posted 2008-02-04 17:41:32 »

despite using netbeans or another java IDE, the build.xml file can be replaced by a easier one, e.g. that one from the Apple XCode IDE for Java Ant. It's shorter and easily configurable by hand-self.
here's a sample of the build-jar target you can find at the CVS repository for my project :
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  
<target name="build-jar" depends="compile" description="Build jar">
  101         <mkdir dir="${dist}"/>
  102         <mkdir dir="${resources.all.dir}"/>
  103         <mkdir dir="${resources.os.all.dir}"/>
  104         <mkdir dir="${resources.os.arch.dir}"/>
  105         <!-- First, copy the HTML into the ${dist} directory. -->
  106         <copy todir="${dist}" file="${html.file}"/>
  107         <!-- ******* resources files to ${dist} directory *****
  108       <copy todir="${dist}/Images">
  109          <fileset dir="${resources.dir}/Images">
  110             <include name="**/*.*"/>
  111          </fileset>
  112       </copy>
  113       <copy todir="${dist}/data">
  114          <fileset refid="data.files"/>
  115       </copy> disable -->
  116         <!-- policy file AppletViewer or java use it -->
  117         <copy file="${policy.file}" todir="${dist}"/>
  118         <!-- run file //-->
  119         <copy file="${run-osx.file}" todir="${dist}"/>
  120         <copy file="${run-win32.file}" todir="${dist}"/>
  121         <jar jarfile="${jarfile}"
  122              basedir="${bin}"
  123              manifest="${Manifest.file}"
  124              update="true"
  125              compress="true">
  126             <!-- Merge library jars into final jar file -->
  127             <zipgroupfileset refid="lib.all.jars"/>
  128             <zipgroupfileset refid="lib.os.all.jars"/>
  129             <zipgroupfileset refid="lib.os.arch.jars"/>
  130             <!-- ****** zip resources ******  -->
  131             <fileset refid="resources.all.files"/>
  132             <fileset refid="resources.os.all.files"/>
  133             <fileset refid="resources.os.arch.files"/>
  134             <!--disable for quicker build -->
  135         </jar>
  136     </target>

see lines 131-133 are the resources to add directly compressed to the .jar archive. it can be fit to your settings. http://sf3jswing.cvs.sourceforge.net/sf3jswing/AnimationDemo3/build.xml?view=markup is the source file. Cool
IMPORTANT NOTICE for the "newless clubies" : resources for inner-.jar usage MUST BE package ORDERED to the CLASSLOADER THAT CALLS FOR THE RESOURCE FILE, e.g. java.lang.Math.class.getResource(file) means that the file is located in the resources directory named /java/lang/ .

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline cylab

JGO Ninja


Medals: 55



« Reply #12 - Posted 2008-02-04 17:53:17 »

Don't replace ant-files of a netbeans generated java project. This would break most of the project properties functionality as well as the library management. Only use custom ant files with freeform projects, but be aware that you will loose some IDE comfort when doing this.

Also I see no real benefits by avoiding the netbeans generated build files, since they are used transparent through the main build.xml which you can customize...

Mathias - I Know What [you] Did Last Summer!
Offline broumbroum

Junior Devvie





« Reply #13 - Posted 2008-02-04 21:48:05 »

alright, but there are plenty of advantages to be able to customize your build ant file. By the way netbeans build.xml properties are not so useful as they can be talked so, above all the library path is always accessible in the project properties which will not affect the build.xml file. Moreover the classpath is changed when the app is run, whereas merging all libraries in the .jar archive is the proper way for minimizing compatibility defection issue.
Well if any of you can build a complete .exe or .app file with netbeans, let us know... but that's not the topic.
 Grin

::::... :..... :::::: ;;;:::™ b23:production 2006 GNU/GPL @ http://b23prodtm.webhop.info
on sf.net: /projects/sf3jswing
Java (1.6u10 plz) Web Start pool
dev' VODcast[/ur
Offline cylab

JGO Ninja


Medals: 55



« Reply #14 - Posted 2008-02-05 00:03:08 »

Actually there is no problem to customize a netbeans build.xml to do anything you want at any build process stage. See the comments in the standard netbeans project's build.xml:

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  
    There exist several targets which are by default empty and which can be 
    used for execution of your tasks. These targets are usually executed
    before and after some main targets. They are:

      -pre-init:                 called before initialization of project properties
      -post-init:                called after initialization of project properties
      -pre-compile:              called before javac compilation
      -post-compile:             called after javac compilation
      -pre-compile-single:       called before javac compilation of single file
      -post-compile-single:      called after javac compilation of single file
      -pre-compile-test:         called before javac compilation of JUnit tests
      -post-compile-test:        called after javac compilation of JUnit tests
      -pre-compile-test-single:  called before javac compilation of single JUnit test
      -post-compile-test-single: called after javac compilation of single JUunit test
      -pre-jar:                  called before JAR building
      -post-jar:                 called after JAR building
      -post-clean:               called after cleaning build products

    (Targets beginning with '-' are not intended to be called on their own.)

    Example of inserting an obfuscator after compilation could look like this:

        <target name="-post-compile">
            <obfuscate>
                <fileset dir="${build.classes.dir}"/>
            </obfuscate>
        </target>

    For list of available properties check the imported
    nbproject/build-impl.xml file.


It's more like implementing abstract methods (with code completion) than writing scripts, but you can do everything you could do in a stand alone ant script. I too have some stand alone ant projects - nothings wrong with that - but there is also nothing wrong with utilizing an existing build template...

Mathias - I Know What [you] Did Last Summer!
Offline Bonbon-Chan

JGO Coder


Medals: 12



« Reply #15 - Posted 2008-02-05 08:21:34 »

So, i put :

1  
2  
3  
4  
<target name="-pre-jar">
        <jar destfile="Music1.jar" basedir="audio"/>
        <jar destfile="Sprites.jar" basedir="sprites"/>
    </target>

in the build.xml

And i have added the 2 jars in the "Libraries", it work fine (even if there is twince the jar file, but it is not a big problem). I have try to put the jar directly in the lib folder but it didn't seem to work (error that it can't delete the "dist" directory)
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.

xFryIx (60 views)
2014-11-13 12:34:49

digdugdiggy (39 views)
2014-11-12 21:11:50

digdugdiggy (32 views)
2014-11-12 21:10:15

digdugdiggy (28 views)
2014-11-12 21:09:33

kovacsa (50 views)
2014-11-07 19:57:14

TehJavaDev (54 views)
2014-11-03 22:04:50

BurntPizza (53 views)
2014-11-03 18:54:52

moogie (68 views)
2014-11-03 06:22:04

CopyableCougar4 (67 views)
2014-11-01 23:36:41

DarkCart (153 views)
2014-11-01 14:51:03
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!