Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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  
  Another dumb Jar question thats magic!  (Read 1098 times)
0 Members and 1 Guest are viewing this topic.
Offline dranonymous

Junior Member




Hoping to become a Java Titan someday!


« Posted 2004-11-05 02:33:32 »

I have an app that I want to jar with its resources.

I have a dir structure such as this -

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
images/fruit/apple.png
............/orange.png
............/xxx.png

images/plants/tree.png
............./shrub.png
............./xxx.png

com/app/MainApp.class
......./xxx.class


The problem is I don't know how many images will be in each dir.  Even if I did, I'm not going to hand code all the names, that would be silly.  If I know ahead of time the specific filename, I can already load that from the jar file.

How do I 'parse' or examine the jar file to get the names out?  I don't have a seperate jar, everything is in one jar.

Help, please!

Thanks,
Dr. A>
Offline Backmask

Junior Member




586: The average IQ needed to understand a PC


« Reply #1 - Posted 2004-11-05 03:57:35 »

Here you go...

http://java.sun.com/developer/JDCTechTips/2004/tt0727.html#2

Offline dranonymous

Junior Member




Hoping to become a Java Titan someday!


« Reply #2 - Posted 2004-11-05 04:17:50 »

Thats mostly what I need, except the jar is the one I'm running in, so I don't neccesarily have its name.

Errr.. This is sorrta weird to explain.  If I take all my files and then jar them up, I have a single jar.  Now run the jar file by doing a -

java -jar myProgram.jar

Inside that jar is where I want to list the contents of the myProgram.jar.

Does that make more sense?

Dr. A>
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bombadil

Senior Member





« Reply #3 - Posted 2004-11-05 08:03:25 »

You could get an URL of one of your classes, for example:
URL url = Yourmain.class.getResource("/package/Yourmain.class")
.. and then ask for the full path of the JAR  with some of the many URL.methods (maybe use some regexp on the result to get just the file name).
Offline oNyx

JGO Coder


Medals: 2


pixels! :x


« Reply #4 - Posted 2004-11-05 08:28:21 »

Well, you could generate lists of the directory content. Load it and load the images specified in that list.

On windows you would generate a list like this:
-open the command line
-change to the drive (eg: x:<return>)
-change to the directory (eg: cd bla<return>cd moo<return>)
-run the dir command with the bare switch and redirect the output to a text file (eg: dir/b *>list.txt)

弾幕 ☆ @mahonnaiseblog
Offline dranonymous

Junior Member




Hoping to become a Java Titan someday!


« Reply #5 - Posted 2004-11-09 14:16:25 »

I have mostly gotten this to work.  Smiley  I can post the code if anyone is interested.  Its biggest help is when you don't know what resources you have in the jar (images, sounds, etc).

A weird thing is that if you run code from a jar its url will start -

file:/c:/stuff/more/application.jar!/MyClass.class

(Linux would just drop the c: part)

If you get the URL when you are running from JWS as a jar you lose the first /.  I've no idea why.

If anyone would like me to post the code, let me know.

As an aside, here's why I don't 'know' what resources I have.

Imagine you are writing an app which alters photos.  So you have a dir which contains photos of all kinds.  You want to be able to just drop a new photo in the directory and have your program load it up.

If you want the convenience and flexability of not having to hard code your image names, you need some way of figuring out what they are at runtime.  If you are running from inside a jar file, then your images are now inside the jar with you as well, so you can use the normal File() classes to determine what you have.  You need to figure out where 'you' are, then open up your jar and locate the jar entries, which are dirs when you extract them.  You get the idea.

Regards,
Dr. A>
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.

Pippogeek (35 views)
2014-09-24 16:13:29

Pippogeek (28 views)
2014-09-24 16:12:22

Pippogeek (17 views)
2014-09-24 16:12:06

Grunnt (40 views)
2014-09-23 14:38:19

radar3301 (23 views)
2014-09-21 23:33:17

BurntPizza (59 views)
2014-09-21 02:42:18

BurntPizza (29 views)
2014-09-21 01:30:30

moogie (34 views)
2014-09-21 00:26:15

UprightPath (47 views)
2014-09-20 20:14:06

BurntPizza (51 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!