Sending files made by `jar xf` to another directory
-
23-12-2020 - |
Question
I have a JAR with a bunch of configs. I'd like to send them to the correct directory without cd'ing there.
Something like jar xf config.jar --MAGIC-PARAM PATH/TO/DIRECTORY
Is there such a thing? If it helps, this will be called by a Buildr extension (Ruby).
Solution
From the API documentation: http://buildr.apache.org/rdoc/classes/Buildr/Unzip.html
unzip(dir => zip_file).target.invoke
OTHER TIPS
Alex's answer is good. If there's some special magic that jar xf
does that makes you prefer it to unzipping (I'm not aware of any), here's another option:
FileUtils.cd('PATH/TO/DIRECTORY') do
system("jar xf '#{_('config.jar')'")
end
It does involve cd'ing, but when you use cd
with a block, the original directory is restored after the block. You will need to use either an absolute path or a path relative to the directory you changed to; I'm using buildr's _
method to get an absolute path for a project-relative file.