File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

extract jar file programatically

 
Cloey Tan
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Cloey Tan
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
http://maven.apache.org/guides/getti...e-minutes.html

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
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Cloey,

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

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic