loadModel from Jar

Do some debugging on your path (that the model is loaded from)

C:Program FilesMozilla Firefoxresourcemodelvp12799.3ds

Does not seem like a legit path to a resource in a jar file....

(also, I think make sure all your jar files are signed; I think they need to be if one is...)

I have had some problems with the resource-locations during the webstart deployment as well, a few weeks ago.

The problem is, that you are not allowed to use this.getClass().getClassLoader().getResource("blaa.3ds") within the code, when you want to deploy it as webstart.

2 Alternatives:



In this way, referring to the resources works in Eclipse and in the deployed jar.

But you still have to check the URLs…

Try to use the ResourceLocator, and set it up like this:

ResourceLocator locator = null;
URL locatorURL = null;

try {
   locatorURL = new URL(this.getClass().getResource(""), relativePathToYourModelLocation);
   locator = new SimpleResourceLocator(locatorURL);
} catch (URISyntaxException e) {
} catch (MalformedURLException e) {
} catch (IOException e) {
} finally {
      .println("VB3DBaseGame:init() - have setup the RESOURCELOCATOR-URL to the following path: "
            + locatorURL);
//In my case all resources(Models,Textures,Audio) are in the same directory.. so use the same locator for those //types.
//Or set up a new locator with the relative path to Audio/Texture for each type, and use this instead.
ResourceLocatorTool.TYPE_TEXTURE, locator);

and use it like:

URL modelUrl = ResourceLocatorTool.locateResource(
            ResourceLocatorTool.TYPE_MODEL, "blaa.3ds");

Here is my code:

protected static Node loadModelJme(String modelNameToLoad){
      Spatial maggie = null;
      try {
            URL modelFile = B3dMain.class.getClassLoader().getResource("data/model/" + modelNameToLoad + ".jme");
            System.out.println("This is " + modelNameToLoad + " "  + modelFile);
            BinaryImporter importer = new BinaryImporter();
            maggie = (Spatial)importer.load(modelFile.openStream());
            //More code goes here

It does work when deployed as Java webstart following the webstart tutorial on the jme wiki. Remember to include your 3ds / jme or whatever (textures included) in your jar file when creating it in i.e Eclipse. Also do a print of the URL to check what folder it is referring to. Make sure that folder exist :) maybe its located under src, or maybe bin, you see the point?

- Jars have to be signed.
- Mime type has to be correct on webserver.
- JNLP has to be correct.

Does it webstart at all? If it does jar signing, mime-types and jnlp is probably correct.

OT: Considered converting the .3ds to .jme for faster loading times btw?

OT: Considered converting the .3ds to .jme for faster loading times btw?

that is only recommended for distributions where the jME XML format is locked into the distributed jME code.
(basically you might want to wait until it's time for a 'release' of your game, and even then make sure to keep the originals handy...)

If you convert all your models, then the jME format changes (which can happen) all of those converted models may not load anymore.

Thanks to all of you for your responses.

  • All of the jars are signed.

  • Mime type is correct on server.

  • JNLP appears to be correct.

    Note, If I comment-out model loading, the skybox and other graphics load and the webstart application works as expected.

    Only fails when trying to load a model.

    I will try your recommendations and let you know how it turns out.


    After some trial and (much) error this variation (found on this fourm) worked in my applet:

URL model = AlienApplet.class.getClassLoader().getResource("resource/model/vp12799.3ds");
      FormatConverter converter = new Md3ToJme();
      ByteArrayOutputStream BO = new ByteArrayOutputStream();
      try {
         converter.convert(model.openStream(), BO);
         Spatial space =(Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray()));
         space.setModelBound(new BoundingBox());

Thanks again to everyone.