JAR – extracting specific files

From the source:

To extract only certain files from a jar file, supply their filenames:

C:\Java> jar xf myFile.jar foo bar

Using wildcards is a shell thing, and you should not expect it to work when extracting from a JAR file (which, as you’ve realized, is the case).

What you can do, is supply a list of the files you want to extract, via the @ modifier:

jar xf my.jar @myfiles.lst

where myfiles.lst would be:

com/my/MyClass.java
com/my/MySecondClass.java

This file could easily be created automatically with creative use of jar tvf, awk and your desired extraction pattern. I’ll leave that as an exercise and/or another SO question 🙂

Or you could use unzip – a JAR file is basically a zip-file.

Cheers,

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)