一个jar文件到底包含什么?

时间:2022-01-04 16:53:50

As an intern, I use company code in my projects and they usually send me a jar file to work with. I add it to the build path in Eclipse and usually all is fine and dandy.

作为实习生,我在我的项目中使用公司代码,他们通常会给我发送一个jar文件。我将它添加到Eclipse的构建路径中,通常一切都很好。

However, I got curious to know, what each class contained and when I try to open one of the classes in the jar file, it tells me that I need a source file.

然而,我很好奇每个类包含什么,当我尝试打开jar文件中的一个类时,它告诉我我需要一个源文件。

What does this mean? I come from a C/C++ background so is a jar similar to an already compiled .o file and all I can see is the .h stuff? Or is there actual code in the jar file that I'm using that's encrypted so I can't read it?

这是什么意思?我来自一个C/ c++背景,那么一个jar和一个已经编译好的。o文件相似,我只能看到。h文件吗?或者我正在使用的jar文件中有加密的代码,所以我无法读取它?

Thanks for all the answers!

谢谢你的回答!

Edit:
Thanks, guys, I knew it was a sort of like an archive but I was confused to why when I tried to open the .class files, I got a bunch of random characters. The output was similar when I tried to open a .o file in C so I just wanted to make sure.
Thanks!

编辑:谢谢,伙计们,我知道这有点像存档,但我不明白为什么当我试图打开。class文件时,我得到了一堆随机的字符。当我尝试在C中打开.o文件时,输出是类似的,所以我只想确保。谢谢!

12 个解决方案

#1


58  

A JAR file is actually just a ZIP file. It can contain anything - usually it contains compiled Java code (*.class), but sometimes also Java sourcecode (*.java).

JAR文件实际上就是一个ZIP文件。它可以包含任何内容——通常它包含编译后的Java代码(*.class),但有时也包含Java源代码(*. Java)。

However, Java can be decompiled - in case the developer obfuscated his code you won't get any useful class/function/variable names though.

但是,Java可以被反编译—如果开发人员混淆了他的代码,您将不会得到任何有用的类/函数/变量名。

#2


44  

However, I got curious to what each class contained and when I try to open one of the classes in the jar file, it tells me that I need a source file.

然而,我很好奇每个类包含什么,当我尝试打开jar文件中的一个类时,它告诉我我需要一个源文件。

A jar file is basically a zip file containing .class files and potentially other resources (and metadata about the jar itself). It's hard to compare C to Java really, as Java byte code maintains a lot more metadata than most binary formats - but the class file is compiled code instead of source code.

jar文件基本上是一个zip文件,包含.class文件和可能的其他资源(以及关于jar本身的元数据)。很难将C和Java进行真正的比较,因为Java字节代码维护的元数据比大多数二进制格式要多——但是类文件是编译代码而不是源代码。

If you either open the jar file with a zip utility or run jar xf foo.jar you can extract the files from it, and have a look at them. Note that you don't need a jar file to run Java code - classloaders can load class data directly from the file system, or from URLs, as well as from jar files.

如果您使用zip实用程序打开jar文件,或者运行jar xf foo。jar您可以从中提取文件,并查看它们。注意,运行Java代码不需要jar文件——类加载器可以直接从文件系统或url以及jar文件加载类数据。

#3


14  

The best way to understand what the jar file contains is by executing this :

理解jar文件包含什么最好的方法是执行以下操作:

Go to command line and execute jar tvf jarfilename.jar

转到命令行并执行jar tvf jarfilename.jar

#4


9  

A jar file is a zip file with some additional files containing metadata. (Despite the .jar extension, it is in zip format, and any utilities that deal with .zip files are also able to deal with .jar files.)

jar文件是包含一些包含元数据的附加文件的zip文件。(尽管有.jar扩展名,但它是zip格式的,任何处理.zip文件的实用程序也可以处理.jar文件。)

http://docs.oracle.com/javase/8/docs/technotes/guides/jar/index.html

http://docs.oracle.com/javase/8/docs/technotes/guides/jar/index.html

Jar files can contain any kind of files, but they usually contain class files and supporting configuration files (properties), graphics and other data files needed by the application.

Jar文件可以包含任何类型的文件,但是它们通常包含类文件和支持配置文件(属性)、图形和应用程序所需的其他数据文件。

Class files contain compiled Java code, which is executable by the Java Virtual Machine.

类文件包含已编译的Java代码,Java虚拟机可以执行这些代码。

http://en.wikipedia.org/wiki/Java_class_file

http://en.wikipedia.org/wiki/Java_class_file

#5


6  

JAR stands for Java ARchive. It's a file format based on the popular ZIP file format and is used for aggregating many files into one. Although JAR can be used as a general archiving tool, the primary motivation for its development was so that Java applets and their requisite components (.class files, images and sounds) can be downloaded to a browser in a single HTTP transaction, rather than opening a new connection for each piece. This greatly improves the speed with which an applet can be loaded onto a web page and begin functioning. The JAR format also supports compression, which reduces the size of the file and improves download time still further. Additionally, individual entries in a JAR file may be digitally signed by the applet author to authenticate their origin.

JAR代表Java存档。它是一种基于流行的ZIP文件格式的文件格式,用于将多个文件聚合为一个文件。虽然JAR可以作为通用的存档工具使用,但是开发它的主要动机是让Java applet及其必需的组件(。可以将类文件、图像和声音下载到单个HTTP事务中的浏览器中,而不是为每一个文件打开一个新的连接。这大大提高了applet加载到web页面并开始运行的速度。JAR格式还支持压缩,这减少了文件的大小,进一步提高了下载时间。此外,JAR文件中的单个条目可以由applet作者进行数字签名,以验证它们的来源。

#6


4  

Jar file contains compiled Java binary classes in the form of *.class which can be converted to readable .java class by decompiling it using some open source decompiler. The jar also has an optional META-INF/MANIFEST.MF which tells us how to use the jar file - specifies other jar files for loading with the jar.

Jar文件包含以*形式编译的Java二进制类。类,通过使用某种开源反编译器对其进行反编译,可以将其转换为可读的.java类。jar还有一个可选的META-INF/MANIFEST。MF,它告诉我们如何使用jar文件——指定其他jar文件来装载jar文件。

#7


2  

JD-GUI is a very handy tool for browsing and decompiling JARs

gui是一个非常方便的工具,用于浏览和反编译jar

#8


1  

A .jar file is akin to a .exe file. In essence, they are both executable zip files (different zip algorithms).

jar文件类似于.exe文件。本质上,它们都是可执行的zip文件(不同的zip算法)。

In a jar file, you will see folders and class files. Each class file is similar to your .o file, and is a compiled java archive.

在jar文件中,您将看到文件夹和类文件。每个类文件与您的.o文件相似,是一个已编译的java存档。

If you wanted to see the code in a jar file, download a java decompiler (located here: http://java.decompiler.free.fr/?q=jdgui) and a .jar extractor (7zip works fine).

如果希望查看jar文件中的代码,请下载一个java反编译器(位于这里:http://java.decompiler.free.fr/?q=jdgui)和一个.jar提取器(7zip工作正常)。

#9


1  

Just check if the aopalliance.jar file has .java files instead of .class files. if so, just extract the jar file, import it in eclipse & create a jar though eclipse. It worked for me.

检查一下aopalliance。jar文件有.java文件而不是.class文件。如果是这样,只需提取jar文件,在eclipse中导入它,并通过eclipse创建一个jar。它为我工作。

#10


0  

A .jar file contains compiled code (*.class files) and other data/resources related to that code. It enables you to bundle multiple files into a single archive file. It also contains metadata. Since it is a zip file it is capable of compressing the data that you put into it.

jar文件包含已编译的代码(*)。类文件)和与该代码相关的其他数据/资源。它允许您将多个文件打包到一个存档文件中。它还包含元数据。由于它是一个zip文件,它可以压缩您放入其中的数据。

Couple of things i found useful.

我发现了一些有用的东西。

http://www.skylit.com/javamethods/faqs/createjar.html

http://www.skylit.com/javamethods/faqs/createjar.html

http://docs.oracle.com/javase/tutorial/deployment/jar/basicsindex.html

http://docs.oracle.com/javase/tutorial/deployment/jar/basicsindex.html

The book OSGi in practice defines JAR files as, "JARs are archive files based on the ZIP file format, allowing many files to be aggregated into a single file. Typically the files contained in the archive are a mixture of compiled Java class files and resource files such as images and documents. Additionally the specification defines a standard location within a JAR archive for metadata — the META-INF folder — and several standard file names and formats within that directly, most important of which is the MANIFEST.MF file."

在实践中,OSGi将JAR文件定义为“JAR是基于ZIP文件格式的归档文件,允许将许多文件聚合到一个文件中。”通常,归档中包含的文件是编译后的Java类文件和资源文件(如图像和文档)的混合。此外,规范还定义了元数据JAR归档文件中的一个标准位置(即META-INF文件夹),以及其中的几个标准文件名和格式,其中最重要的是清单。MF文件。”

#11


0  

As per my understanding Jar file is same as Zip but has executable files.

根据我的理解,Jar文件与Zip文件相同,但是有可执行文件。

If you do not have executable files in Jar then it would be same as Zip file, I mean to say why go to Jar.

如果在Jar中没有可执行文件,那么它将与Zip文件相同,我的意思是说为什么要去Jar。

Since Jar file has executable files, they can be easily loaded on to your code and easily transferred to others to use it.

由于Jar文件具有可执行文件,因此可以很容易地将它们加载到您的代码中,并很容易地转移到其他人使用它。

#12


0  

Jar( Java Archive) contains group of .class files.

Jar(Java存档)包含一组.class文件。

1.To create Jar File (Zip File)

1。要创建Jar文件(Zip文件)

 if one .class (say, Demo.class) then use command jar -cvf NameOfJarFile.jar Demo.class (usually it’s not feasible for only one .class file)

 if more than one .class (say, Demo.class , DemoOne.class) then use command jar -cvf NameOfJarFile.jar Demo.class DemoOne.class

 if all .class is to be group (say, Demo.class , DemoOne.class etc) then use command jar -cvf NameOfJarFile.jar *.class

2.To extract Jar File (Unzip File)

2。提取Jar文件(Unzip文件)

    jar -xvf NameOfJarFile.jar

3.To display table of content

3所示。显示内容表

    jar -tvf NameOfJarFile.jar

#1


58  

A JAR file is actually just a ZIP file. It can contain anything - usually it contains compiled Java code (*.class), but sometimes also Java sourcecode (*.java).

JAR文件实际上就是一个ZIP文件。它可以包含任何内容——通常它包含编译后的Java代码(*.class),但有时也包含Java源代码(*. Java)。

However, Java can be decompiled - in case the developer obfuscated his code you won't get any useful class/function/variable names though.

但是,Java可以被反编译—如果开发人员混淆了他的代码,您将不会得到任何有用的类/函数/变量名。

#2


44  

However, I got curious to what each class contained and when I try to open one of the classes in the jar file, it tells me that I need a source file.

然而,我很好奇每个类包含什么,当我尝试打开jar文件中的一个类时,它告诉我我需要一个源文件。

A jar file is basically a zip file containing .class files and potentially other resources (and metadata about the jar itself). It's hard to compare C to Java really, as Java byte code maintains a lot more metadata than most binary formats - but the class file is compiled code instead of source code.

jar文件基本上是一个zip文件,包含.class文件和可能的其他资源(以及关于jar本身的元数据)。很难将C和Java进行真正的比较,因为Java字节代码维护的元数据比大多数二进制格式要多——但是类文件是编译代码而不是源代码。

If you either open the jar file with a zip utility or run jar xf foo.jar you can extract the files from it, and have a look at them. Note that you don't need a jar file to run Java code - classloaders can load class data directly from the file system, or from URLs, as well as from jar files.

如果您使用zip实用程序打开jar文件,或者运行jar xf foo。jar您可以从中提取文件,并查看它们。注意,运行Java代码不需要jar文件——类加载器可以直接从文件系统或url以及jar文件加载类数据。

#3


14  

The best way to understand what the jar file contains is by executing this :

理解jar文件包含什么最好的方法是执行以下操作:

Go to command line and execute jar tvf jarfilename.jar

转到命令行并执行jar tvf jarfilename.jar

#4


9  

A jar file is a zip file with some additional files containing metadata. (Despite the .jar extension, it is in zip format, and any utilities that deal with .zip files are also able to deal with .jar files.)

jar文件是包含一些包含元数据的附加文件的zip文件。(尽管有.jar扩展名,但它是zip格式的,任何处理.zip文件的实用程序也可以处理.jar文件。)

http://docs.oracle.com/javase/8/docs/technotes/guides/jar/index.html

http://docs.oracle.com/javase/8/docs/technotes/guides/jar/index.html

Jar files can contain any kind of files, but they usually contain class files and supporting configuration files (properties), graphics and other data files needed by the application.

Jar文件可以包含任何类型的文件,但是它们通常包含类文件和支持配置文件(属性)、图形和应用程序所需的其他数据文件。

Class files contain compiled Java code, which is executable by the Java Virtual Machine.

类文件包含已编译的Java代码,Java虚拟机可以执行这些代码。

http://en.wikipedia.org/wiki/Java_class_file

http://en.wikipedia.org/wiki/Java_class_file

#5


6  

JAR stands for Java ARchive. It's a file format based on the popular ZIP file format and is used for aggregating many files into one. Although JAR can be used as a general archiving tool, the primary motivation for its development was so that Java applets and their requisite components (.class files, images and sounds) can be downloaded to a browser in a single HTTP transaction, rather than opening a new connection for each piece. This greatly improves the speed with which an applet can be loaded onto a web page and begin functioning. The JAR format also supports compression, which reduces the size of the file and improves download time still further. Additionally, individual entries in a JAR file may be digitally signed by the applet author to authenticate their origin.

JAR代表Java存档。它是一种基于流行的ZIP文件格式的文件格式,用于将多个文件聚合为一个文件。虽然JAR可以作为通用的存档工具使用,但是开发它的主要动机是让Java applet及其必需的组件(。可以将类文件、图像和声音下载到单个HTTP事务中的浏览器中,而不是为每一个文件打开一个新的连接。这大大提高了applet加载到web页面并开始运行的速度。JAR格式还支持压缩,这减少了文件的大小,进一步提高了下载时间。此外,JAR文件中的单个条目可以由applet作者进行数字签名,以验证它们的来源。

#6


4  

Jar file contains compiled Java binary classes in the form of *.class which can be converted to readable .java class by decompiling it using some open source decompiler. The jar also has an optional META-INF/MANIFEST.MF which tells us how to use the jar file - specifies other jar files for loading with the jar.

Jar文件包含以*形式编译的Java二进制类。类,通过使用某种开源反编译器对其进行反编译,可以将其转换为可读的.java类。jar还有一个可选的META-INF/MANIFEST。MF,它告诉我们如何使用jar文件——指定其他jar文件来装载jar文件。

#7


2  

JD-GUI is a very handy tool for browsing and decompiling JARs

gui是一个非常方便的工具,用于浏览和反编译jar

#8


1  

A .jar file is akin to a .exe file. In essence, they are both executable zip files (different zip algorithms).

jar文件类似于.exe文件。本质上,它们都是可执行的zip文件(不同的zip算法)。

In a jar file, you will see folders and class files. Each class file is similar to your .o file, and is a compiled java archive.

在jar文件中,您将看到文件夹和类文件。每个类文件与您的.o文件相似,是一个已编译的java存档。

If you wanted to see the code in a jar file, download a java decompiler (located here: http://java.decompiler.free.fr/?q=jdgui) and a .jar extractor (7zip works fine).

如果希望查看jar文件中的代码,请下载一个java反编译器(位于这里:http://java.decompiler.free.fr/?q=jdgui)和一个.jar提取器(7zip工作正常)。

#9


1  

Just check if the aopalliance.jar file has .java files instead of .class files. if so, just extract the jar file, import it in eclipse & create a jar though eclipse. It worked for me.

检查一下aopalliance。jar文件有.java文件而不是.class文件。如果是这样,只需提取jar文件,在eclipse中导入它,并通过eclipse创建一个jar。它为我工作。

#10


0  

A .jar file contains compiled code (*.class files) and other data/resources related to that code. It enables you to bundle multiple files into a single archive file. It also contains metadata. Since it is a zip file it is capable of compressing the data that you put into it.

jar文件包含已编译的代码(*)。类文件)和与该代码相关的其他数据/资源。它允许您将多个文件打包到一个存档文件中。它还包含元数据。由于它是一个zip文件,它可以压缩您放入其中的数据。

Couple of things i found useful.

我发现了一些有用的东西。

http://www.skylit.com/javamethods/faqs/createjar.html

http://www.skylit.com/javamethods/faqs/createjar.html

http://docs.oracle.com/javase/tutorial/deployment/jar/basicsindex.html

http://docs.oracle.com/javase/tutorial/deployment/jar/basicsindex.html

The book OSGi in practice defines JAR files as, "JARs are archive files based on the ZIP file format, allowing many files to be aggregated into a single file. Typically the files contained in the archive are a mixture of compiled Java class files and resource files such as images and documents. Additionally the specification defines a standard location within a JAR archive for metadata — the META-INF folder — and several standard file names and formats within that directly, most important of which is the MANIFEST.MF file."

在实践中,OSGi将JAR文件定义为“JAR是基于ZIP文件格式的归档文件,允许将许多文件聚合到一个文件中。”通常,归档中包含的文件是编译后的Java类文件和资源文件(如图像和文档)的混合。此外,规范还定义了元数据JAR归档文件中的一个标准位置(即META-INF文件夹),以及其中的几个标准文件名和格式,其中最重要的是清单。MF文件。”

#11


0  

As per my understanding Jar file is same as Zip but has executable files.

根据我的理解,Jar文件与Zip文件相同,但是有可执行文件。

If you do not have executable files in Jar then it would be same as Zip file, I mean to say why go to Jar.

如果在Jar中没有可执行文件,那么它将与Zip文件相同,我的意思是说为什么要去Jar。

Since Jar file has executable files, they can be easily loaded on to your code and easily transferred to others to use it.

由于Jar文件具有可执行文件,因此可以很容易地将它们加载到您的代码中,并很容易地转移到其他人使用它。

#12


0  

Jar( Java Archive) contains group of .class files.

Jar(Java存档)包含一组.class文件。

1.To create Jar File (Zip File)

1。要创建Jar文件(Zip文件)

 if one .class (say, Demo.class) then use command jar -cvf NameOfJarFile.jar Demo.class (usually it’s not feasible for only one .class file)

 if more than one .class (say, Demo.class , DemoOne.class) then use command jar -cvf NameOfJarFile.jar Demo.class DemoOne.class

 if all .class is to be group (say, Demo.class , DemoOne.class etc) then use command jar -cvf NameOfJarFile.jar *.class

2.To extract Jar File (Unzip File)

2。提取Jar文件(Unzip文件)

    jar -xvf NameOfJarFile.jar

3.To display table of content

3所示。显示内容表

    jar -tvf NameOfJarFile.jar