[英]Extracting .jar file with command line
I am trying to extract the files from a.jar file.我正在尝试从 a.jar 文件中提取文件。 How do I do that using command line?
我如何使用命令行来做到这一点?
I am running Windows 7我正在运行 Windows 7
To extract the files from a jar file, use
x
, as in:要从 jar 文件中提取文件,请使用
x
,如下所示:C:\\Java> jar xf myFile.jar
To extract only certain files from a jar file, supply their filenames:
要仅从 jar 文件中提取某些文件,请提供它们的文件名:
C:\\Java> jar xf myFile.jar foo bar
The folder where jar
is probably isn't C:\\Java
for you, on my Windows partition it's: jar
所在的文件夹对您来说可能不是C:\\Java
,在我的 Windows 分区上它是:
C:\Program Files (x86)\Java\jdk[some_version_here]\bin
Unless the location of jar
is in your path environment variable, you'll have to specify the full path/run the program from inside the folder.除非
jar
的位置在您的路径环境变量中,否则您必须指定完整路径/从文件夹内运行程序。
EDIT: Here's another article, specifically focussed on extracting JARs: http://docs.oracle.com/javase/tutorial/deployment/jar/unpack.html编辑:这是另一篇文章,专门针对提取 JAR: http : //docs.oracle.com/javase/tutorial/deployment/jar/unpack.html
请注意,jar 文件是一个 Zip 文件,任何 Zip 工具(例如 7-Zip)都可以查看 jar 的内部。
在 Ubuntu 中:
unzip file.jar -d dir_name_where_extracting
You can use the following command: jar xf rt.jar
可以使用以下命令:
jar xf rt.jar
Where X
stands for extraction and the f
would be any options that indicate that the JAR file from which files are to be extracted is specified on the command line, rather than through stdin.其中
X
代表提取, f
将是任何选项,指示要从中提取文件的 JAR 文件是在命令行上指定的,而不是通过 stdin 指定的。
jar xf myFile.jar
change myFile to name of your file将 myFile 更改为您的文件名
this will save the contents in the current folder of .jar file这会将内容保存在 .jar 文件的当前文件夹中
that should do :)应该这样做:)
Java has a class specifically for zip files and one even more specifically for Jar Files. Java 有一个专门用于 zip 文件的类,还有一个专门用于 Jar 文件的类。
java.util.jar.JarOutputStream
java.util.jar.JarInputStream
using those you could, on a command from the console, using a scanner set to system.in使用那些你可以,在控制台的命令上,使用设置为 system.in 的扫描仪
Scanner console = new Scanner(System.in);
String input = console.nextLine();
then get all the components and write them as a file.然后获取所有组件并将它们写入文件。
JarEntry JE = null;
while((JE = getNextJarEntry()) != null)
{
//do stuff with JE
}
You can also use java.util.zip.ZipInputStream instead, as seeing a JAR file is in the same format as a ZIP file, ZipInputStream will be able to handle the Jar file, in fact JarInputStream actually extends ZipInputStream.您也可以使用 java.util.zip.ZipInputStream 代替,因为看到 JAR 文件与 ZIP 文件的格式相同,ZipInputStream 将能够处理 Jar 文件,实际上 JarInputStream 实际上扩展了 ZipInputStream。
an alternative is also instead of getNextJarEntry, to use getNextEntry另一种方法是使用 getNextEntry 代替 getNextJarEntry
Given a file named Me.Jar:给定一个名为 Me.Jar 的文件:
Use the Java jar
command -- I am using jdk1.8.0_31 so I would type使用 Java
jar
命令——我使用的是 jdk1.8.0_31 所以我会输入
C:\\Program Files (x86)\\Java\\jdk1.8.0_31\\bin\\jar xf me.jar C:\\Program Files (x86)\\Java\\jdk1.8.0_31\\bin\\jar xf me.jar
That should extract the file to the folder bin.这应该将文件解压缩到文件夹 bin。 Look for the file .class in my case my Me.jar contains a Valentine.class
在我的情况下查找文件 .class 我的 Me.jar 包含一个 Valentine.class
Type java Valentine
and press Enter and your message file will be opened.键入
java Valentine
并按 Enter,您的消息文件将被打开。
I had the same issue and the jar command did not work.我遇到了同样的问题,并且 jar 命令不起作用。 I made a copy of the jar file and changed the extension to.zip.
我复制了 jar 文件并将扩展名更改为.zip。 Then right click on the.zip file and select 'Extract All'.
然后右键单击 .zip 文件和 select 'Extract All'。 This extracted all the files.
这提取了所有文件。
要将 jar 解压缩到指定文件夹中,请通过命令提示符使用此命令
C:\Java> jar xf myFile.jar -C "C:\tempfolder"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.