I have searched for this for a while now, but cant seem to figure it out. I want to extract a directory from a jar/zip file, and save it recursively to a path on the filesystem in java. Anyone know how I might do this?
Asked
Active
Viewed 1.0k times
3
-
Do you mean how to do this from within java code? – sinelaw Sep 25 '11 at 09:08
-
Yes, sorry, should have been a bit more clear then the tag – Hans Sep 25 '11 at 09:10
-
1[What Have You Tried?](http://mattgemmell.com/2008/12/08/what-have-you-tried/) What *specific* problems have you struck? – Andrew Thompson Sep 25 '11 at 09:47
-
I have tried, and made success in extracting a file in itself, I want to extract one directory only from the jar. – Hans Sep 25 '11 at 09:51
-
I cant find a way to extract only that one directory. – Hans Sep 25 '11 at 09:57
-
Does this answer your question? [How to write a Java program which can extract a JAR file and store its data in specified directory (location)?](https://stackoverflow.com/questions/1529611/how-to-write-a-java-program-which-can-extract-a-jar-file-and-store-its-data-in-s) – Didier L Jun 22 '22 at 08:34
2 Answers
5
I know that the original question was actualy doing this programmatically.
But as it wasn't clear enough I guess many users (like me) ends up here when they just want to unzip a directory out of the jar using the jar command.
jar -xvf <your>.jar <required-dir>
E.g. extract META-INF directory out of some.jar
jar -xvf some.jar META-INF
to list the content of the jar use
jar -tvf some.jar

Haim Raman
- 11,508
- 6
- 44
- 70
5
An answer from this thread might give a good feeling how/where to start:
Simply put, it's java.util.jar
you're looking for.