Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
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  
  [SOLVED] Applet and App walk into a jar.  (Read 3078 times)
0 Members and 1 Guest are viewing this topic.
Offline jonjava
« Posted 2012-04-23 10:33:59 »


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:

 - Main.class
 - Applet.class
 + bin
 + resources

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?

Offline Danny02
« Reply #1 - Posted 2012-04-23 11:07:31 »

mm in my case it just works in either case with getResourceStream (from the Class class)
Offline ReBirth
« Reply #2 - Posted 2012-04-23 11:18:55 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jonjava
« Reply #3 - Posted 2012-04-23 13:51:57 »

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

Offline jonjava
« Reply #4 - Posted 2012-04-23 17:20:08 »

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. ._.


Offline ReBirth
« Reply #5 - Posted 2012-04-24 10:47:59 »

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

Offline ra4king

JGO Kernel

Medals: 471
Projects: 3
Exp: 5 years

I'm the King!

« Reply #6 - Posted 2012-04-29 22:15:14 »

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

Offline ReBirth
« Reply #7 - Posted 2012-04-30 01:21:29 »

There are no differences from Java 6 to Java 7 in resource loading... persecutioncomplex
You said. I just not bothered to search it. persecutioncomplex

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Archive (57 views)
2017-02-27 19:41:49

Riven (65 views)
2017-02-27 17:26:59

numerical (436 views)
2017-02-21 07:32:16

numerical (437 views)
2017-02-21 07:31:46

theagentd (551 views)
2017-02-18 13:42:33

theagentd (547 views)
2017-02-18 13:35:16

h.pernpeintner (1722 views)
2017-01-24 22:39:11

h.pernpeintner (1681 views)
2017-01-24 22:38:32

Galdo (2262 views)
2017-01-12 13:44:09

Archive (2182 views)
2017-01-02 05:31:41
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21 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‑
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!