使用命令行提取.jar文件

时间:2021-06-06 13:29:32

I am trying to extract the files from a .jar file. How do I do that using command line?

我试图从.jar文件中提取文件。如何使用命令行执行此操作?

I am running Windows 7

我正在运行Windows 7

8 个解决方案

#1


94  

From the docs:

来自文档:

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:

在我的Windows分区上,jar可能不是C:\ Java的文件夹:

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

#2


23  

Note that a jar file is a Zip file, and any Zip tool (such as 7-Zip) can look inside the jar.

请注意,jar文件是Zip文件,任何Zip工具(例如7-Zip)都可以查看jar内部。

#3


12  

In Ubuntu:

在Ubuntu中:

unzip file.jar -d dir_name_where_extracting

解压缩file.jar -d dir_name_where_extracting

#4


7  

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。

#5


2  

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

#6


2  

jar xf myFile.jar
change myFile to name of your file
this will save the contents in the current folder of .jar file
that should do :)

jar xf myFile.jar将myFile更改为你文件的名称,这会将内容保存在应该执行的.jar文件的当前文件夹中:)

#7


0  

Given a file named Me.Jar:

给定一个名为Me.Jar的文件:

  1. Go to cmd
  2. 转到cmd
  3. Hit Enter
  4. 按Enter键
  5. 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. Look for the file .class in my case my Me.jar contains a Valentine.class

这应该将文件解压缩到文件夹bin。在我的例子中查找文件.class我的Me.jar包含一个Valentine.class

Type java Valentine and press Enter and your message file will be opened.

输入java Valentine并按Enter键,将打开您的消息文件。

#8


-2  

To extract the jar into specified folder use this command via command prompt

要将jar解压缩到指定的文件夹,请通过命令提示符使用此命令

C:\Java> jar xf myFile.jar -C "C:\tempfolder"

#1


94  

From the docs:

来自文档:

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:

在我的Windows分区上,jar可能不是C:\ Java的文件夹:

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

#2


23  

Note that a jar file is a Zip file, and any Zip tool (such as 7-Zip) can look inside the jar.

请注意,jar文件是Zip文件,任何Zip工具(例如7-Zip)都可以查看jar内部。

#3


12  

In Ubuntu:

在Ubuntu中:

unzip file.jar -d dir_name_where_extracting

解压缩file.jar -d dir_name_where_extracting

#4


7  

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。

#5


2  

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

#6


2  

jar xf myFile.jar
change myFile to name of your file
this will save the contents in the current folder of .jar file
that should do :)

jar xf myFile.jar将myFile更改为你文件的名称,这会将内容保存在应该执行的.jar文件的当前文件夹中:)

#7


0  

Given a file named Me.Jar:

给定一个名为Me.Jar的文件:

  1. Go to cmd
  2. 转到cmd
  3. Hit Enter
  4. 按Enter键
  5. 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. Look for the file .class in my case my Me.jar contains a Valentine.class

这应该将文件解压缩到文件夹bin。在我的例子中查找文件.class我的Me.jar包含一个Valentine.class

Type java Valentine and press Enter and your message file will be opened.

输入java Valentine并按Enter键,将打开您的消息文件。

#8


-2  

To extract the jar into specified folder use this command via command prompt

要将jar解压缩到指定的文件夹,请通过命令提示符使用此命令

C:\Java> jar xf myFile.jar -C "C:\tempfolder"