• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jars and magic problems  RSS feed

 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

Thanks,
Aaron R>
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aaron,
I want to help you..
You can use java.util.zip.ZipFile to read the content of jar file.
This is my code



This application will read jar's name via args[0] which is inputed by user.
I try to read jdbc-mysql.jar and I have result like this



Hope this help...
Correct me if i am wrong...

thanks
daniel
 
Aaron Roberts
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Daniel. That is mostly what I want to do. The problem is, I need to get a list of the files in the jar my application is running from.

So if you typed -

java -jar mygame.jar

I want to get a list of the files in that jar while its running. Do you see how its slightly different than knowing the name ahead of time?

Thanks,
Aaron R>
 
Fisher Daniel
Ranch Hand
Posts: 582
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Aaron,
I don't know whether my understanding is correct or not.
If you want that application can be run as runtime, you can change main method with the other one.
Example


On that method, we return Enumeration to the caller. Then the caller can extract that enumeration object according its purpose.
Your caller method can print the result into console or file or something else...

Correct me if I am wrong...
Hope this help

daniel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!