Packaging a JME jar (including assets)

Hello all,

I am working with JME3 (bundled with Netbeans), and I use the following workflow in order to package a jar file (with all libraries and everything needed to run included): http://java.sun.com/developer/technicalArticles/java_warehouse/single_jar/



In regular Netbeans this method works fine, but in JME bundled Netbeans, there seems to be a problem with the loading of any imported assets (throws AssetNotFoundException). Assets don’t seem to be included in the jar. I also tried to call assetManager.loadModel(filePath) using an absolute path (e.g. C:model.mesh.xml) but with no luck…



Any ideas how to solve this?

Is there another way to package the jar file together with any imported assets?



Thanks,

1 Like

If all of your assets are in the assets folder, and you load them with the asset manager, then it will work fine. The SDK does all of this for you, just go to project->properties->application->desktop and select how you want it bundled there.

I think he wants it all in one jar. You can just pack all jars from dist/ and dist/lib/ to one jar in a -post-jar target in build.xml

I strongly discourage using one single jar file though, you can not make incremental updates or replace libraries and for some LGPL libraries its even forbidden to package them in a single jar (because it has to be a library, not part of your “executable”). As @Sploreg said, the SDK packages all assets in a jar for you and later it will also allow to separate it to have e.g. incremental updates for your application.

Btw, its not “NetBeans”, it uses the NetBeans platform and the same plugins to edit code but its not the NetBeans IDE. We do not hide the fact that it bases on the same tools as the NetBeans IDE but this is a separate application, we are not affiliated with the NetBeans project.

1 Like

Sploreg, thank you very much for the useful tip!

Since I am working on the Cinematic JME library, every class that I create is conceptually a “video clip”. Moreover, I need these classes to be created programmatically (based on a number of parameters), hence the following question:

Where can I find the java command that actually creates the jar file (the one that is automatically created and stored in dist folder)? Is there a way that I can “reproduce” this command so that I can execute it through code?



Thanks,

Just put them in your assets folder. If you plan to do this in-game then you will have to deal with more issues like java class loaders and the likes anyway. The actual code is in nbproject/assets-impl.xml but again, I don’t think it’ll help you if putting the assets in the src/ or assets/ folder doesn’t.

(my) SOLUTION:

I found a lot of useful information/solutions here: http://www.ibm.com/developerworks/java/library/j-onejar/

I think that the optimum solution for what I am trying to do (and what I finally implemented) is to create (this is done once) a “generic” jar with all libraries needed (not the jars themselves but the UNCOMPRESSED class folders that is included in any jar you need to use) together with any assets, and then use the update-jar java command (http://www.iam.ubc.ca/guides/javatut99/jar/basics/update.html) to update the “generic” jar with the class that represents the “animation script”, in order to create a single-stand-alone executable jar (containing all libs and assets) that serves as an animation cutscene “clip”.

Just add an ant target that combines all jars from dist/ and dist/lib, its not hard. Still you take away the option to replace just parts of the app (e.g. to add new assets or a new version of lwjgl).

The one that I implemented (I remind you that I need to do it PROGRAMMATICALLY) automatically takes care of any new assets/classes that need to be added.

what Normen means is that you have to deploy the whole package on each delivery. you can’t deploy the new/changed assets only.

On games that have a lot of assets this can be a problem.

Anyway if your solution suits your needs it’s fine IMO.

What I meant is that (given that you have all your assets ready and included in the “generic” jar together with any libraries) you just have to update the jar with a (main) class that contains the cinematic script events that animate those assets. Anyway, what I am doing is definitely not intended for a game, but just for generating cut-scenes and have them as stand-alone executable jars (as an alternative to “record” them to an avi file, which I suppose that it would in any case be a simpler solution ;).

@yannischris said:
The one that I implemented (I remind you that I need to do it PROGRAMMATICALLY) automatically takes care of any new assets/classes that need to be added.

The solution I suggested would also happen PROGRAMMATICALLY..

didn’t realize…

Could you provide more info on doing this ? I know nothing about ant.

Can it be done in Launch4J too ?

I tried inserting the following in build.xml, but it didn’t work

 <target name="combine-jars">
    <jar destfile="Reved_Out.jar">
        <zipgroupfileset dir="lib" includes="*.jar"/>
    </jar>
</target>

I rolled some dice to figure out which of the many different specific “didn’t work” it might be and as usual it landed on a very interesting response: “Computer overheats and continues to get hotter until it glows like the sun”

Wow. You should shut your machine down and leave the room until temperatures cool back down and then do a safe boot to see if the issue persists.

:wink:

1 Like

If it’s supposed to create a file called Reved_Out.jar that contains all the jar files in lib, then that file wasn’t created. That’s how I know it didn’t work.

Yep, that is one of the 100 or so “didn’t work”… my dice roll must have been wrong. Thanks for clarifying.

1 Like

Then it is working as intended. :smiley:

1 Like