Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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 2220 times)
0 Members and 1 Guest are viewing this topic.
Offline dranonymous

Junior Devvie

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 -




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!

Dr. A>
Offline Backmask

Junior Devvie

586: The average IQ needed to understand a PC

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

Here you go...

Offline dranonymous

Junior Devvie

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 Devvie

« 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 Devvie

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 -


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

Dr. A>
Pages: [1]
  ignore  |  Print  

EgonOlsen (74 views)
2018-06-10 19:43:48

EgonOlsen (55 views)
2018-06-10 19:43:44

EgonOlsen (75 views)
2018-06-10 19:43:20

DesertCoockie (255 views)
2018-05-13 18:23:11

nelsongames (154 views)
2018-04-24 18:15:36

nelsongames (154 views)
2018-04-24 18:14:32

ivj94 (895 views)
2018-03-24 14:47:39

ivj94 (156 views)
2018-03-24 14:46:31

ivj94 (808 views)
2018-03-24 14:43:53

Solater (172 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!