wood burning stoves
The moose likes Java in General and the fly likes extract jar file programatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "extract jar file programatically" Watch "extract jar file programatically" New topic

extract jar file programatically

Cloey Tan
Ranch Hand

Joined: Feb 03, 2009
Posts: 60
Dear all,

Using java, is there a way to extract jar file such that i can look for certain package, and list out out all the files belong to that particular package? Hope for some guidelines and helpful resouces.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

A jar file is actually just a zip file. You can use the java.util.jar package to look through a jar file and find whatever entries you want; for example, this prints out the name of each entry in a jar file:

[Jess in Action][AskingGoodQuestions]
Cloey Tan
Ranch Hand

Joined: Feb 03, 2009
Posts: 60
Thanks it works. but i have another few questions to ask here
I create a project and build it with maven using the following simple example:

Then, i add a new file, called test.xml under the main root of the project, then use the above code to loop through the files, test.xml doesnt seem to get listed. And i found from this site http://www.cezwright.com/tools/java/jar_war_ear.htm, that jar doesnt include xml file, but then pom.xml get listed, but not test.xml which has been newly added.

Besides, if i were to package everything in war, how to do the settings in pom.xml?
Martijn Verburg

Joined: Jun 24, 2003
Posts: 3275

Hi Cloey,

Can you please re-post your last question in our Ant, Maven and Build tools forum, you'll get better help there

Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
I agree. Here's the link: http://aspose.com/file-tools
subject: extract jar file programatically
It's not a secret anymore!