Java Webstart Problem

Hello,

I am trying to make a webstart version of my game, but i have a problem. Everything works fine if I startup the game from my local disc, and have my data (models, textures, …) in a directory; although all this data is also in the jar. When I startup the jar from somewhere else I don’t need the data dir. Only when I try to run the webstart application. What am I doind wrong here ?

Here is the webstart code:


<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" codebase="http://users.pandora.be/kozen/demos" href="Sample.jnlp">
<information>
  <title>JOGL Sample</title>
  <vendor>K. Development</vendor>
  <description>JOGL Demo</description>
</information>
<offline-allowed/>
<security>
      <all-permissions/>
</security>
<resources>
  <j2se version="1.4+" />
  <jar href="Sample.jar"/>
  <jar href="Resources/jogl.jar"/>
</resources>
<resources os="Windows">
    <j2se version="1.4+"/> 
    <nativelib href="Resources/jogl-natives-win32.jar"/>
  </resources> 
  <resources os="Linux" arch="i386">
    <j2se version="1.4+"/> 
    <nativelib href="Resources/jogl-natives-linux.jar"/>
  </resources> 
  <resources os="OSX">
    <j2se version="1.4+"/> 
    <nativelib href="Resources/jogl-natives-macosx.jar"/>
  </resources> 
  <resources os="Mac OS X">
    <j2se version="1.4+"/> 
    <nativelib href="Resources/jogl-natives-macosx.jar"/>
  </resources> 

<application-desc main-class="Sample" />
</jnlp>

Regards,
Kenzo

It’s impossible to tell without knowing how you load your data. If you limit yourself to ClassLoader.getResourceAsStream() and similar APIs for fetching your data then things should work fine off the local disk and with Java Web Start. See the source code for the JOGL demos at http://jogl-demos.dev.java.net/ and the JNLP files they use. In particular look at VertexProgRefract and its fetching of its images.

@Guoshima:
are you aware of the fact that “Resources” has to be a folder on your server?

some exception traces and the like would be really helpful.

Sorry for long dealy, was out away for a few days, but I still have the same problem. To load my files I simply use the following methods:


public static URL getResourceURL(final String filename) throws IOException {
        // Try to load resource from jar
        URL url = ClassLoader.getSystemResource(filename);
        System.out.println("Resource url: "+url);
        // If not found in jar, then load from disk
        if (url == null) {
            return new URL("file", "localhost", filename);
        } else {
            return url;
        }
    }

    public static InputStream getResourceAsStream(final String filename) throws IOException {
        // Try to load resource from jar
        InputStream stream = ClassLoader.getSystemResourceAsStream(filename);
            System.out.println("Resource stream: "+stream);
        // If not found in jar, then load from disk
        if (stream == null) {
            return new FileInputStream(filename);
        } else {
            return stream;
        }
    }

When i try to run a simple sample program from a jar, this gives no errors. He always finds the extra jars for JOGL, … but he can’t seam to read my data, which is also in the jar. I get a null pointer when I try to create the data. This is the error:


Resource stream: null

java.io.FileNotFoundException: data\glass.png (Het Systeem kan het opgegeven pad niet vinden)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.<init>(Unknown Source)
      at java.io.FileInputStream.<init>(Unknown Source)
      at ResourceRetriever.getResourceAsStream(ResourceRetriever.java:30)
      at TextureReader.readImage(TextureReader.java:29)
      at TextureReader.readTexture(TextureReader.java:23)
      at TextureReader.readTexture(TextureReader.java:15)
      at Sample.createTexture(Sample.java:427)
      at Sample.init(Sample.java:511)
      at net.java.games.jogl.impl.GLDrawableHelper.init(GLDrawableHelper.java:68)
      at net.java.games.jogl.GLCanvas$InitAction.run(GLCanvas.java:187)
      at net.java.games.jogl.impl.windows.WindowsGLContext.makeCurrent(WindowsGLContext.java:144)
      at net.java.games.jogl.impl.windows.WindowsOnscreenGLContext.makeCurrent(WindowsOnscreenGLContext.java:110)
      at net.java.games.jogl.impl.GLContext.setRenderingThread(GLContext.java:253)
      at net.java.games.jogl.GLCanvas.setRenderingThread(GLCanvas.java:148)
      at net.java.games.jogl.Animator$1.run(Animator.java:89)
      at java.lang.Thread.run(Unknown Source)

I placed my little demo online at http://users.pandora.be/koze/demos/. If you check the java console, you’ll see the error, and you can also check that the data is in the Jar. I also placed my source code inside the jar. Hope someone can find my error, so i can put my game online :slight_smile:

Error:

The requested URL /koze/demos/ was not found on this server.

sorry typo: http://users.pandora.be/kozen/demos/

Ok, just so you know - I get exactly the same problem here.

System: Win XP (SP2), Java 1.4.2_04

It looks like your developing off the same texureReader and resource file classes as I. I’ve got a long list of developmental progressions for my own work today, but hopefully will be able to fit into it all a little JNLP test by the end of the day.

Looking at your JNLP file, I can see nothing that stands out as incorrect, but instead of your format which follows:

<jnlp spec="1.0+" codebase="http://users.pandora.be/kozen/demos" href="Sample.jnlp">
<information>
  <title>JOGL Sample</title>
  <vendor>K. Development</vendor>
  <description>JOGL Demo</description>
</information>

I would use this (not sure if it will have any effect whatsoever):

<jnlp 
  spec="1.0+"
  codebase="http://users.pandora.be/kozen/demos/" 
  href="Sample.jnlp">
<information>
  <title>JOGL Sample</title>
  <vendor>K. Development</vendor>
  <description>JOGL Demo</description>
</information>

java.io.FileNotFoundException: data\glass.png

Don’t use backslashes ::slight_smile:

strange … but I don’t write backslashes in my code. Java makes backslashes out of them. Will try the native getDefaultSeperator or something … know it excists, just have to find how and where :slight_smile:

In fact you don’t want to use Files at all in webstart applications. However, your “ResourceRetriever” class would indicate that you’re aware of this… but FileInputStream simple won’t work to access files from a jar?

Odd… ???

Kev

Will try the native getDefaultSeperator or something

Ops… my bad. Nah there is no need to. Just keep the usual slashes and everthing is fine… and a leading slash is also a good idea… eg “/snd/blam.ogg”.

well … I tried the native seperator by calling System.getProperties(“file.separator”), but then I always get “”. And the jar executable won’t work either then.

Changed everything back to normal, and added the filename also in the output, and I get this:


System separator: \
Resource stream: null with filename: data/glass.png
java.io.FileNotFoundException: data\glass.png (Het systeem kan het opgegeven pad niet vinden)
      at java.io.FileInputStream.open(Native Method)
      at java.io.FileInputStream.<init>(Unknown Source)      at java.io.FileInputStream.<init>(Unknown Source)
...

so you see that I call py using “data/glass.png”, but then he changed it to data\glass.png … presume this is a windows thing. So I don’t know what I am doing wrong here … !

All these people who made Java Webstart games, how do they do it to load their files … ? I presume all the data is also in the jar …

Nah. There is nothing wrong.

It gets converted to the path style of the underlying OS… so it’s perfectly normal that you get a ‘’ there at the end (if you are using windows).

And yes, the images go into the jar file, too. So do you have a sub dir in the jar called “data” with a file called “glass.png” in it?

[quote]and a leading slash is also a good idea… eg “/snd/blam.ogg”.
[/quote]
I’ve found that a leading slash will work fine for locally run (ie, from IDE) apps, yet fail when in webstart. Leaving it off works in both.

yip … there is subdir data with glass.png in it. And it works fine when I perform following command: java -jar Sample.jar

perhaps there is something wrong with the Jarsigner or so. How do you need to sign a jar. I simple used the following method: (from http://java.sun.com/developer/technicalArticles/Programming/jnlp/)

is the this correct ?

Mmmh? ???

http://people.freenet.de/ki_onyx/rmfjuke.jnlp (*) (~96kb)

Leading slashes used there.

(* Sounds like poo without a soundbank [you get one with the sdk but none with the jre])

[quote]In fact you don’t want to use Files at all in webstart applications. However, your “ResourceRetriever” class would indicate that you’re aware of this… but FileInputStream simple won’t work to access files from a jar?

Odd… ???

Kev
[/quote]
This is what I mentioned a couple of weeks ago in our ResourceLoader class for survivor (thinks: perhaps we should post that code here somewhere? It’s quite nice with the override…)

Currently, Sun JVM’s have dodgy support for URL’s and File’s and JAR-URL’s and their interaction. One side-effect is that you CANNOT use “file://” URL’s in some places in java where you would expect you could. Another is that you don’t seem to be able to use “peeking-inside-a-JAR” URL’s in places where you might expect to be able to - in particular, you CANNOT use FileInputStream on these things.

…which, IIRC, is all wrong: the JVM has a clever system of “protocols” where you should be able to add a single “protocol” and that makes all URL’s everwhere understand that protocol. But all I know is that it hasn’t worked properly any of the last 3 or 4 times I’ve tried it.

So:

  • never use FileInputStream in a JAR environment
  • never use File in a JAR environment (without FIS, it’s largely useless anyway, but IIRC it doesn’t understand JAR’s either - so you can’t make use of the .exists() methods etc, making it ENTIRELY useless)
  • never rely upon URL-based methods, because in various situations they just don’t work (when logic would suggest they should)
  • when using getResourceAsStream, bear in mind that it WILL return you a non-null InputStream when IT CANNOT FIND THE RESOURCE!

…which is why I took Kev’s ResourceLoader class and added lots of special-casing code so that it could do what most of the above methods OUGHT to do by default, but don’t: you give it the name of a file you want to load and it gets an InputStream either from a JAR or from a File, automatically picking whichever it can find…

thanx for the help … and would you mind sharing that loader with us. Might be very very handy for a few of us … !

well … I still haven’t fixed my web start problem yet. Might be interesting to have a little test code or something from somebody which uses webstart and works fine. The rest I will find out myself then … really can’t see the problem. I litterly tried the method from the tutorial at the Java Games Factory, but nothing. He can’t find it in the JNLP classloader … !

I looked at your files and everything looks fine, all I can say is are you absolutely sure that your jar file contains the latest version of your class files? Your code looks correct and your jar looks correct (as far as I know, I’m new to webstart myself). I’d say start over from scratch on your jar file, delete the old one, and re-add everything and sign it. I looked through your source and jar files but actually compiling your code is one step past where I’m willing to go tonight :stuck_out_tongue: