[SOLVED] Applet and App walk into a jar.

Hi,

I’ve been stuck on an annoying problem all morning and I realized I’ve been debugging an inner bug for who knows how long until I realized this outer bug and now I need to re-debug the inner bug… The information available on the net are annoyingly inaccurately varied.

So, I’d appreciate answers to a few simple questions regarding loading resources from within a jar so I can stop hitting my head against the wall:)

  1. Absolute paths are bad. Is there a universal way for both Applets and normal Applications to get at resources from within the same jar?

  2. If not. What are the separate good ways for relatively getting at resources for Applets and Applications?

Consider this scenario:

giraffe.jar
\
 - Main.class
 - Applet.class
 + bin
  \Game.class
  \...
 + resources
  \Ball.png
  \GiraffeSprite.jpg
  \music.wav

In the case of Applets, the html ARCHIVE is set to “giraffes.jar” and CODE to “Applet.class”.

So, whether you load your resources from the Game.class or Applet.class, what’s the perfect line of code to reach the “resources” folder and its godly items?

mm in my case it just works in either case with getResourceStream (from the Class class)

Yes just use

URL url = this.getClass().getClassLoader().getResource("resources/Ball.png");

Hmm, damn. That means something else is wrong. More debugging… :confused:

Well, I found the problem. It was java7. Switched to 1.6.u31 and voila no problems. Why did this solve it? I don’t know and I’m too tired to care. Java7 is such a douchebag.

My goodness the amount of time wasted. ._.

Grr.

ra4king (or maybe other?) had mentioned before that there’s different of java6 and java7 in resource stream.

There are no differences from Java 6 to Java 7 in resource loading… :persecutioncomplex:

You said. I just not bothered to search it. :persecutioncomplex: