13

Is there a way to extract a jar file to a specific directory? For instance, I'm in foo directory, which contains the subfolder bar; all my jars files are at the same level at bar. So I passed the command jar xf my.jar -C bar/ However when I went to bar folder, the files were not extracted. Is there a way for me to do it without having to move the jar file to bar?

Thanks

fabricemarcelin
  • 1,719
  • 6
  • 25
  • 34

2 Answers2

27

I don't think jar supports this, but unzip does. Try:

unzip my.jar -d bar

The behaviour is the same as the jar command, because jar files are the same as zip files.

dogbane
  • 266,786
  • 75
  • 396
  • 414
  • $ man jar says: '-C dir Temporarily changes directories (cd dir) during execution of the jar command while processing the following inputfiles argument. Its operation is intended to be similar to the -C option of the UNIX tar utility.' –  Jan 23 '12 at 10:52
  • 4
    It also says that the -C option can only be used with the -c (create) or -u (update) options. It won't work with the -x (extract) option. – dogbane Jan 23 '12 at 10:55
4

"Is there a way for me to do it without having to move the jar file to bar?"

You can do this by entering bar and executing the extract command from there, like this:

cd bar
jar xf ../my.jar