如何使用单个命令在UNIX文件系统中提取JAR并使用JAR命令指定其目标目录? [英] How do you extract a JAR in a UNIX filesystem with a single command and specify its target directory using the JAR command?

查看:137
本文介绍了如何使用单个命令在UNIX文件系统中提取JAR并使用JAR命令指定其目标目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Python脚本,我在其中执行UNIX系统命令。我有一个名为Binaries.war的
war存档,它位于名为Portal.ear的ear存档中。

I am creating a Python script within which I am executing UNIX system commands. I have a war archive named Binaries.war which is within an ear archive named Portal.ear

Portal ear文件位于/ home / foo中/ bar /

The Portal ear file resides in, say /home/foo/bar/

jar xf /home/foo/bar/Portal.ear Binaries.war

将/home/foo/bar/Portal.ear存档中的Binaries.war文件解压缩到我正在运行的当前目录中来自。

Will extract the Binaries.war file out of the /home/foo/bar/Portal.ear archive into the current directory I am running the script from.

如何使用一个命令指定要提取的目标目录?
我想做这样的事情将Binaries.war提取到目录/ home / foo / bar / baz

How do you specify a target directory to be extracted to using just one command? I would like to do something like this to extract Binaries.war into the directory /home/foo/bar/baz

jar xf /home/foo/bar/Portal.ear Binaries.war [into target directory /home/foo/bar/baz]

我搜索了JAR手册页中的选项,似乎无法找到一种简单的方法来执行此操作。当然,我可以将存档提取到我当前的目录中,然后使用mv移动它,但我想一次性完成此操作,而不是随机播放目录和文件。

I searched the the JAR man page for options and can't seem to find a simple way to do this. Of course I can extract the archive into my current directory and then move it using mv but I'd like to do this in one shot and not shuffle directories and files around.

推荐答案

如果你的jar文件已经有一个如图所示的绝对路径名,那就特别容易:

If your jar file already has an absolute pathname as shown, it is particularly easy:

cd /where/you/want/it; jar xf /path/to/jarfile.jar

也就是说,你有通过Python更改执行的shell您的目录,然后运行提取。

That is, you have the shell executed by Python change directory for you and then run the extraction.

如果您的jar文件还没有绝对路径名,那么您必须将相对名称转换为绝对名称(通过为其添加前缀)使用当前目录的路径)这样 jar 可以在更改目录后找到它。

If your jar file does not already have an absolute pathname, then you have to convert the relative name to absolute (by prefixing it with the path of the current directory) so that jar can find it after the change of directory.

唯一令人担心的问题是路径名中的空白。

The only issues left to worry about are things like blanks in the path names.

这篇关于如何使用单个命令在UNIX文件系统中提取JAR并使用JAR命令指定其目标目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆