Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (525)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  Accessing resources from a jar outside a jar  (Read 1522 times)
0 Members and 1 Guest are viewing this topic.
Offline barfy

Junior Devvie




The evidence of things not seen


« Posted 2004-08-10 15:25:47 »

The scenario is:

I've got 2 jars - 1 contains all the class files (including the main executable file), the other all the images i need.

The question is:

How do I load the images from within the image jar file in the application deployed using java web start?

Thanks heaps in advance Smiley
Online kevglass

« JGO Spiffy Duke »


Medals: 208
Projects: 24
Exp: 18 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2004-08-10 16:40:25 »

1  
2  
3  
4  
5  
getClass().getClassLoader().getResource("myimagename.png")); 

or

getClass().getClassLoader().getResourceAsStream("mystreamabledata.dat");


Kev


Offline barfy

Junior Devvie




The evidence of things not seen


« Reply #2 - Posted 2004-08-11 00:55:53 »

Sorry, I think I was being unclear with my problem description. What I meant was:

I've got 2 jars - 1 jar contains all the program code (ie, .class, .java and 1 dll file), the other contains all images and sound files that I would like to use within the application, which I plan to distribute using just webstart and as seperately downloadable jar files.

The problem is:

How do I load/reference the image and sound files within the "image and sound" jar from the "program code" jar?


1  
2  
3  
4  
5  
getClass().getClassLoader().getResource("myimagename.png"));  
 
or
 
getClass().getClassLoader().getResourceAsStream("mystreamabledata.dat");  


I've tried that and simply "getClass().getResource()" which I think is an equivalent statement. Both won't work since the images are located within a jar that is outside the program jar.

Besides that, is there a convenient way to load a library dll file that is jar'red together with the program code?




Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #3 - Posted 2004-08-11 01:05:46 »

First and foremost, you need to put a '/' in front of your path names. Secondly, you can put a dud class in the images and sounds JAR to tell the JVM where to look. e.g.:
1  
public class FileLocater {}

1  
FileLocater.class.getResource("/myimage.png");


Hope this helps! :-)

Java Game Console Project
Last Journal Entry: 12/17/04
Offline gangrel-br

Junior Devvie




Java and Scala! Thats the game =)


« Reply #4 - Posted 2004-08-11 01:10:24 »

To make your code jar see the files in the sound / image jar, you can add

1  
Class-Path: SoundImage.jar


to the manifest of the code jar. After that, I *think* the 'getResource()' will work (not tried).

As for loading dll, I would be happy to find a good way to load then from a jar... What I do now is to put the dll's in the same dir as the game's jar.

Paulo "JCranky" Siqueira
Offline barfy

Junior Devvie




The evidence of things not seen


« Reply #5 - Posted 2004-08-11 02:30:54 »

Quote
To make your code jar see the files in the sound / image jar, you can add

1  
Class-Path: SoundImage.jar


to the manifest of the code jar. After that, I *think* the 'getResource()' will work (not tried).


Yup, that worked very well.  Smiley

Actually, I tried that before and it didn't work then because of a "Classpath" typo from this article (which I referred to): http://www.rgagnon.com/javadetails/java-0319.html

Thanks for cluing me in.

Quote

First and foremost, you need to put a '/' in front of your path names.


It works properly without that on Windows. Under what circumstances would that statement fail without the '/'?

Quote

Secondly, you can put a dud class in the images and sounds JAR to tell the JVM where to look. e.g.:
1  
public class FileLocater {} 


1  
2  
FileLocater.class.getResource("/myimage.png"); 
 



Hope this helps!  



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

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (67 views)
2014-11-26 15:22:04

toopeicgaming1999 (58 views)
2014-11-26 15:20:36

toopeicgaming1999 (12 views)
2014-11-26 15:20:08

SHC (24 views)
2014-11-25 12:00:59

SHC (24 views)
2014-11-25 11:53:45

Norakomi (29 views)
2014-11-25 11:26:43

Gibbo3771 (24 views)
2014-11-24 19:59:16

trollwarrior1 (37 views)
2014-11-22 12:13:56

xFryIx (76 views)
2014-11-13 12:34:49

digdugdiggy (53 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org 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‑gaming.org
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!