.jar和.dll文件之间的差异

时间:2022-06-09 03:47:12

I am learning Java these days and I've spent a lot of time with .NET so when I want to export or import libraries, they are usually be in .dll format which is called assembly in .Net environment and they are compiled to IL and they can have resources like images, xml, audio and son on, any ways.

我学习Java的这些天,我花了很多时间与。net当我想导出或导入库,它们通常是在组装在。net . dll的格式被称为环境和编译IL和他们可以有资源(如图像、xml、音频和儿子,任何方式。

I am wondering same process in Java as well. I've read documents but they actually confused me little bit and to clarify things out I need your help guys.

在Java中我也想知道同样的过程。我读过一些文件,但他们实际上把我弄糊涂了,我需要你的帮助。

Questions:

问题:

  1. .NET Assembly is same thing as java .jar?
  2. .NET程序集和java .jar是一样的吗?
  3. .dll contains compiled IL code and .jar contains complied .class/byte code files?
  4. .dll包含编译后的IL代码,.jar包含已编译的。类/字节码文件?
  5. They say resources, what kind of resources we are talking about here? Images, .txt files, etc. or all of them possible?

    他们说资源,我们在这里讨论的是什么资源?图片、.txt文件等等,还是所有可能的?

  6. I've examined AWS (Amazon Web Service API for java) and I saw three .jar file and they are

    我检查了AWS (java的Amazon Web服务API),看到了三个.jar文件

    1. aws-java-sdk-1.1.1.jar
    2. aws-java-sdk-1.1.1.jar
    3. aws-java-sdk-1.1.1-javadoc.jar
    4. aws-java-sdk-1.1.1-javadoc.jar
    5. aws-java-sdk-1.1.1-sources.jar
    6. aws-java-sdk-1.1.1-sources.jar

and they contain .class files - java documentation in html format and .java files which are still not compiled. So then I've realized .jar doesn't just include compiled byte codes (.class) and also other things.

它们包含.class文件- html格式的java文档和.java文件,这些文件仍然没有被编译。然后我意识到。jar不仅仅包含编译后的字节码(.class)和其他东西。

  1. When I want to import java libraries, will I always need to import .jar files?
  2. 当我想导入java库时,是否总是需要导入.jar文件?
  3. When I want to export my own java libraries, should I need to export in .jar file.
  4. 当我想要导出我自己的java库时,是否需要导出.jar文件。

Thanks for help in advance.

提前谢谢你的帮助。

3 个解决方案

#1


70  

Is a .NET Assembly is same thing as java .jar?

.NET程序集和java .jar是一样的吗?

They play the same role, yes.

是的,他们扮演着同样的角色。

.dll contains compiled IL code and .jar contains complied .class/byte code files?

.dll包含编译后的IL代码,.jar包含已编译的。类/字节码文件?

Yes. Although JARs are just zip files (you can open them in your favorite Zip tool), so they can really contain just about anything.

是的。尽管jar文件只是zip文件(你可以在你最喜欢的zip工具中打开它们),所以它们真的可以包含任何东西。

They say resources, what kind of resources we are talking about here? Images, .txt files, etc. or all of them possible?

他们说资源,我们在这里讨论的是什么资源?图片、.txt文件等等,还是所有可能的?

Any file type is allowed in a JAR. Your Java code can access the contents of files within the jar via, for example, getResourceAsStream or getResource. Obviously .class files in a JAR are treated specially (as bytecode).

在JAR中允许任何文件类型。您的Java代码可以通过getresourstream或getResource访问jar中的文件内容。显然,JAR中的类文件是专门处理的(如字节码)。

I've examined AWS (Amazon Web Service API for java) and I saw three .jar file and they are: aws-java-sdk-1.1.1.jar, aws-java-sdk-1.1.1-javadoc.jar, aws-java-sdk-1.1.1-sources.jar

我检查了AWS (java的Amazon Web服务API),看到了三个.jar文件,它们是:AWS -java-sdk-1.1.1。aws-java-sdk-1.1.1-javadoc jar。jar,aws-java-sdk-1.1.1-sources.jar

The above packaging is fairly common. Sometimes people use .jar as an alternative file extension to .zip. I find this practice confusing, but it is not uncommon, and Amazon has done it in this case. I think this practice became more common with the launch of Maven, which stores reference source code in files named .jar.

上述包装相当普遍。有时人们使用.jar作为.zip的替代文件扩展名。我觉得这种做法令人困惑,但这并不罕见,亚马逊在这种情况下也这么做过。我认为这种做法在Maven的发布中变得更加普遍,Maven将引用源代码存储在名为.jar的文件中。

aws-java-sdk-1.1.1.jar - This is the only file necessary for compilation and execution. It contains the classes (.class files) and resources necessary for the library to function.

aws-java-sdk-1.1.1。jar -这是编译和执行所需的唯一文件。它包含类(。类文件)和库运行所需的资源。

aws-java-sdk-1.1.1-sources.jar - This is just a zip file that contains the source code (.java files) for the library. It is not necessary for compilation or execution. It is provided to help you troubleshoot problems you may encounter while using the library. You could unzip this file and read the source code from your hard drive. However, your IDE can probably utilize this file directly by creating a "source attachment" to the main library JAR. With this library->source association set up in your IDE, your IDE will be able to show you the source code of the library when you use your IDE's "Go to Definition" feature on a library class.

aws-java-sdk-1.1.1-sources。jar -这只是一个包含源代码的zip文件(。java文件)用于库。不需要编译或执行。它可以帮助您解决在使用库时可能遇到的问题。您可以解压此文件并从硬盘驱动器中读取源代码。但是,您的IDE可能可以通过创建主库JAR的“源附件”直接使用这个文件。有了这个库——在IDE中设置>源代码关联,当您在库类上使用IDE的“Go to Definition”特性时,您的IDE将能够显示库的源代码。

aws-java-sdk-1.1.1-javadoc.jar - This is just a zip file that contains the JavaDoc for the library. Again, it is not necessary for compilation or execution. JavaDoc is just HTML, so you could unzip this file and read the JavaDoc HTML directly from your hard drive. However, most IDEs can create a "javadoc attachment" to the main library, which allows you to pull up context-sensitive JavaDoc for the library from within the IDE. Actually, most IDEs can generate the JavaDoc on the fly from the -sources.jar, so I rarely use javadoc jars anymore.

aws-java-sdk-1.1.1-javadoc。jar -这只是一个zip文件,其中包含库的JavaDoc。同样,它也不需要编译或执行。JavaDoc只是HTML,所以您可以解压这个文件,并直接从硬盘驱动器读取JavaDoc HTML。但是,大多数IDE都可以在主库中创建一个“javadoc附件”,它允许您从IDE中提取上下文敏感的javadoc。实际上,大多数ide都可以从源生成JavaDoc。jar,所以我很少再使用javadoc jar了。

When I want to import java libraries, will I always need to import .jar files?

当我想导入java库时,是否总是需要导入.jar文件?

It's usually called "adding JARs to the classpath", but yes. You pretty much always need to help Java find all the JARs you're using by constructing a classpath whenever you build or execute. In general, using JARs and classpaths is a much more manual and explicit process than using DLLs in .NET. For example: Java has no direct equivalent of .NET's "global assembly cache"; also vanilla Java will not automatically load .jars from the working directory.

它通常被称为“向类路径中添加jar”,但是是的。您几乎总是需要帮助Java找到在构建或执行时构造类路径时所使用的所有jar。一般来说,使用jar和类路径比在。net中使用dll要手工和显式得多。例如:Java没有直接等价于。net的“全局程序集缓存”;此外,香草Java不会自动从工作目录加载.jars。

There are a few other techniques for creating a more "automatic" feeling classpath, but they are kind of advanced: Manifest.MF classpaths are possible, for example -- but this approach is used infrequently as it is brittle. As of Java 6, Java has limited support for using wildcards in the classpath.

有一些其他的技术可以创建更“自动”的感觉类路径,但是它们有点高级:Manifest。例如,MF类路径是可能的,但由于这种方法很脆弱,所以很少使用这种方法。在Java 6中,Java对在类路径中使用通配符的支持是有限的。

When I want to export my own java libraries, should I need to export in .jar file

当我想要导出我自己的java库时,是否需要导出.jar文件

This is standard, yes.

这是标准的,是的。

#2


8  

I can answer part of that question :-)

我可以回答这个问题的一部分:

As I understand it, a jar is just a "Java Archive" file. It can contain anything you want, but is most often used to distribute binary versions of libraries. It can also be used for distributing executables -- double-clicking a JAR file will launch the application, if that's how it's been packaged.

按照我的理解,jar只是一个“Java归档”文件。它可以包含任何您想要的内容,但通常用于分发二进制版本的库。它也可以用于分发可执行文件——双击一个JAR文件将启动应用程序,如果它是这样打包的。

As such, it may be difficult to tell what a particular jar file is intended for. For example, what is aws-java-sdk-1.1.1-sources.jar?. Is it a self-installer? A compressed code archive? Without reading documentation, it's anybody's guess.

因此,很难说一个特定的jar文件是用来做什么的。例如,什么是aws-java-sdk-1.1.1 source .jar?这是一个self-installer吗?一个压缩的代码归档吗?没有阅读文档,这是任何人的猜测。


Edit: case in point, I just downloaded the JAI jar file assuming it was a binary build of the library. But in fact, it contains the installer application.

编辑:我刚刚下载了JAI jar文件,假设它是库的二进制版本。但实际上,它包含安装程序应用程序。

#3


7  

To answer this specific question.

回答这个问题。

  1. aws-java-sdk-1.1.1.jar
  2. aws-java-sdk-1.1.1.jar
  3. aws-java-sdk-1.1.1-javadoc.jar
  4. aws-java-sdk-1.1.1-javadoc.jar
  5. aws-java-sdk-1.1.1-sources.jar
  6. aws-java-sdk-1.1.1-sources.jar

The 1) is the compiler java archive file (jar), which in .NET is called a DLL. The 2) is the javadoc. An HTML documentation of java classes (found in 1)) along with method description. The 3) is the source code (java files) of 1).

1)是编译器java归档文件(jar),在。net中它被称为DLL。2)是javadoc。java类的HTML文档(见1)以及方法描述。3)是1的源代码(java文件)。

  1. When I want to import java libraries, will I always need to import .jar files?
  2. 当我想导入java库时,是否总是需要导入.jar文件?
  3. When I want to export my own java libraries, should I need to export in .jar file.
  4. 当我想要导出我自己的java库时,是否需要导出.jar文件。

For 1) If you need to use a class that is found in a jar file, then you'll need to import that jar into your project.

对于1)如果您需要使用在jar文件中找到的类,那么您需要将该jar导入到您的项目中。

For 2) You don't need to. You can bundle your dependency jars into your library or package each into their own jars and import them into your project.

2)你不需要。您可以将依赖项jar捆绑到库中,或者将每个jar打包到它们自己的jar中,并将它们导入到项目中。

  1. .NET Assembly is same thing as java .jar? Answer: Yes.
  2. .NET程序集和java .jar是一样的吗?答:是的。
  3. .dll contains compiled IL code and .jar contains complied .class/byte code files? Answer: .jar files is an archived file of java resources, classes, images/icons/etc. that is necessary for an application, just like in .DLL. Class files contains compile java source codes (Called java bytecode).
  4. .dll包含编译后的IL代码,.jar包含已编译的。类/字节码文件?答:.jar文件是java资源、类、图像/图标等的存档文件。这对于应用程序是必要的,就像在. dll中一样。类文件包含编译java源代码(称为java字节码)。

#1


70  

Is a .NET Assembly is same thing as java .jar?

.NET程序集和java .jar是一样的吗?

They play the same role, yes.

是的,他们扮演着同样的角色。

.dll contains compiled IL code and .jar contains complied .class/byte code files?

.dll包含编译后的IL代码,.jar包含已编译的。类/字节码文件?

Yes. Although JARs are just zip files (you can open them in your favorite Zip tool), so they can really contain just about anything.

是的。尽管jar文件只是zip文件(你可以在你最喜欢的zip工具中打开它们),所以它们真的可以包含任何东西。

They say resources, what kind of resources we are talking about here? Images, .txt files, etc. or all of them possible?

他们说资源,我们在这里讨论的是什么资源?图片、.txt文件等等,还是所有可能的?

Any file type is allowed in a JAR. Your Java code can access the contents of files within the jar via, for example, getResourceAsStream or getResource. Obviously .class files in a JAR are treated specially (as bytecode).

在JAR中允许任何文件类型。您的Java代码可以通过getresourstream或getResource访问jar中的文件内容。显然,JAR中的类文件是专门处理的(如字节码)。

I've examined AWS (Amazon Web Service API for java) and I saw three .jar file and they are: aws-java-sdk-1.1.1.jar, aws-java-sdk-1.1.1-javadoc.jar, aws-java-sdk-1.1.1-sources.jar

我检查了AWS (java的Amazon Web服务API),看到了三个.jar文件,它们是:AWS -java-sdk-1.1.1。aws-java-sdk-1.1.1-javadoc jar。jar,aws-java-sdk-1.1.1-sources.jar

The above packaging is fairly common. Sometimes people use .jar as an alternative file extension to .zip. I find this practice confusing, but it is not uncommon, and Amazon has done it in this case. I think this practice became more common with the launch of Maven, which stores reference source code in files named .jar.

上述包装相当普遍。有时人们使用.jar作为.zip的替代文件扩展名。我觉得这种做法令人困惑,但这并不罕见,亚马逊在这种情况下也这么做过。我认为这种做法在Maven的发布中变得更加普遍,Maven将引用源代码存储在名为.jar的文件中。

aws-java-sdk-1.1.1.jar - This is the only file necessary for compilation and execution. It contains the classes (.class files) and resources necessary for the library to function.

aws-java-sdk-1.1.1。jar -这是编译和执行所需的唯一文件。它包含类(。类文件)和库运行所需的资源。

aws-java-sdk-1.1.1-sources.jar - This is just a zip file that contains the source code (.java files) for the library. It is not necessary for compilation or execution. It is provided to help you troubleshoot problems you may encounter while using the library. You could unzip this file and read the source code from your hard drive. However, your IDE can probably utilize this file directly by creating a "source attachment" to the main library JAR. With this library->source association set up in your IDE, your IDE will be able to show you the source code of the library when you use your IDE's "Go to Definition" feature on a library class.

aws-java-sdk-1.1.1-sources。jar -这只是一个包含源代码的zip文件(。java文件)用于库。不需要编译或执行。它可以帮助您解决在使用库时可能遇到的问题。您可以解压此文件并从硬盘驱动器中读取源代码。但是,您的IDE可能可以通过创建主库JAR的“源附件”直接使用这个文件。有了这个库——在IDE中设置>源代码关联,当您在库类上使用IDE的“Go to Definition”特性时,您的IDE将能够显示库的源代码。

aws-java-sdk-1.1.1-javadoc.jar - This is just a zip file that contains the JavaDoc for the library. Again, it is not necessary for compilation or execution. JavaDoc is just HTML, so you could unzip this file and read the JavaDoc HTML directly from your hard drive. However, most IDEs can create a "javadoc attachment" to the main library, which allows you to pull up context-sensitive JavaDoc for the library from within the IDE. Actually, most IDEs can generate the JavaDoc on the fly from the -sources.jar, so I rarely use javadoc jars anymore.

aws-java-sdk-1.1.1-javadoc。jar -这只是一个zip文件,其中包含库的JavaDoc。同样,它也不需要编译或执行。JavaDoc只是HTML,所以您可以解压这个文件,并直接从硬盘驱动器读取JavaDoc HTML。但是,大多数IDE都可以在主库中创建一个“javadoc附件”,它允许您从IDE中提取上下文敏感的javadoc。实际上,大多数ide都可以从源生成JavaDoc。jar,所以我很少再使用javadoc jar了。

When I want to import java libraries, will I always need to import .jar files?

当我想导入java库时,是否总是需要导入.jar文件?

It's usually called "adding JARs to the classpath", but yes. You pretty much always need to help Java find all the JARs you're using by constructing a classpath whenever you build or execute. In general, using JARs and classpaths is a much more manual and explicit process than using DLLs in .NET. For example: Java has no direct equivalent of .NET's "global assembly cache"; also vanilla Java will not automatically load .jars from the working directory.

它通常被称为“向类路径中添加jar”,但是是的。您几乎总是需要帮助Java找到在构建或执行时构造类路径时所使用的所有jar。一般来说,使用jar和类路径比在。net中使用dll要手工和显式得多。例如:Java没有直接等价于。net的“全局程序集缓存”;此外,香草Java不会自动从工作目录加载.jars。

There are a few other techniques for creating a more "automatic" feeling classpath, but they are kind of advanced: Manifest.MF classpaths are possible, for example -- but this approach is used infrequently as it is brittle. As of Java 6, Java has limited support for using wildcards in the classpath.

有一些其他的技术可以创建更“自动”的感觉类路径,但是它们有点高级:Manifest。例如,MF类路径是可能的,但由于这种方法很脆弱,所以很少使用这种方法。在Java 6中,Java对在类路径中使用通配符的支持是有限的。

When I want to export my own java libraries, should I need to export in .jar file

当我想要导出我自己的java库时,是否需要导出.jar文件

This is standard, yes.

这是标准的,是的。

#2


8  

I can answer part of that question :-)

我可以回答这个问题的一部分:

As I understand it, a jar is just a "Java Archive" file. It can contain anything you want, but is most often used to distribute binary versions of libraries. It can also be used for distributing executables -- double-clicking a JAR file will launch the application, if that's how it's been packaged.

按照我的理解,jar只是一个“Java归档”文件。它可以包含任何您想要的内容,但通常用于分发二进制版本的库。它也可以用于分发可执行文件——双击一个JAR文件将启动应用程序,如果它是这样打包的。

As such, it may be difficult to tell what a particular jar file is intended for. For example, what is aws-java-sdk-1.1.1-sources.jar?. Is it a self-installer? A compressed code archive? Without reading documentation, it's anybody's guess.

因此,很难说一个特定的jar文件是用来做什么的。例如,什么是aws-java-sdk-1.1.1 source .jar?这是一个self-installer吗?一个压缩的代码归档吗?没有阅读文档,这是任何人的猜测。


Edit: case in point, I just downloaded the JAI jar file assuming it was a binary build of the library. But in fact, it contains the installer application.

编辑:我刚刚下载了JAI jar文件,假设它是库的二进制版本。但实际上,它包含安装程序应用程序。

#3


7  

To answer this specific question.

回答这个问题。

  1. aws-java-sdk-1.1.1.jar
  2. aws-java-sdk-1.1.1.jar
  3. aws-java-sdk-1.1.1-javadoc.jar
  4. aws-java-sdk-1.1.1-javadoc.jar
  5. aws-java-sdk-1.1.1-sources.jar
  6. aws-java-sdk-1.1.1-sources.jar

The 1) is the compiler java archive file (jar), which in .NET is called a DLL. The 2) is the javadoc. An HTML documentation of java classes (found in 1)) along with method description. The 3) is the source code (java files) of 1).

1)是编译器java归档文件(jar),在。net中它被称为DLL。2)是javadoc。java类的HTML文档(见1)以及方法描述。3)是1的源代码(java文件)。

  1. When I want to import java libraries, will I always need to import .jar files?
  2. 当我想导入java库时,是否总是需要导入.jar文件?
  3. When I want to export my own java libraries, should I need to export in .jar file.
  4. 当我想要导出我自己的java库时,是否需要导出.jar文件。

For 1) If you need to use a class that is found in a jar file, then you'll need to import that jar into your project.

对于1)如果您需要使用在jar文件中找到的类,那么您需要将该jar导入到您的项目中。

For 2) You don't need to. You can bundle your dependency jars into your library or package each into their own jars and import them into your project.

2)你不需要。您可以将依赖项jar捆绑到库中,或者将每个jar打包到它们自己的jar中,并将它们导入到项目中。

  1. .NET Assembly is same thing as java .jar? Answer: Yes.
  2. .NET程序集和java .jar是一样的吗?答:是的。
  3. .dll contains compiled IL code and .jar contains complied .class/byte code files? Answer: .jar files is an archived file of java resources, classes, images/icons/etc. that is necessary for an application, just like in .DLL. Class files contains compile java source codes (Called java bytecode).
  4. .dll包含编译后的IL代码,.jar包含已编译的。类/字节码文件?答:.jar文件是java资源、类、图像/图标等的存档文件。这对于应用程序是必要的,就像在. dll中一样。类文件包含编译java源代码(称为java字节码)。