.jar和.dll文件之间的差异 [英] Difference between .jar and .dll file

查看:2485
本文介绍了.jar和.dll文件之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习Java的这些天,我花了很多时间与.NET,所以当我想要导出或导入库,他们通常是.dll文件格式被称为组件.NET环境中,他们是编译为IL和他们能有这样的图片,XML,音频和儿子,任何方式的资源。



我想知道同样的过程在Java中也是如此。我读过的文档,但他们居然弄得我一点,澄清事情了,我需要你的帮助球员



问题:




  1. .NET程序集是一样的东西如Java的.jar?

  2. .dll文件包含编译的IL代码和.jar包含符合的.class /字节码文件?

  3. 他们说的资源,有什么样的资源,我们这里所说的?图片,txt文件等,或所有这些可能的?


  4. 我已经研究AWS(亚马逊Web服务API的Java),我看到了三个。 jar文件,它们是




    1. AWS-Java的SDK-1.1.1.jar

    2. AWS -java-SDK-1.1.1-javadoc.jar

    3. AWS-Java的SDK-1.1.1-sources.jar




和它们包​​含.class文件 - HTML格式的Java文档,哪些是还没有编译.java文件。于是我意识到的.jar并不仅仅包括编译字节代码(的.class)以及其他的事情。




  1. 当我想导入Java库,将我总是需要进口.jar文件?

  2. 当我想导出自己的Java库,我应该需要在.jar文件导出。



感谢您提前帮助。


解决方案

是一个.NET程序集是一样的东西如Java的.jar?



他们发挥同样的作用,是的。



.dll文件包含编译的IL代码和.jar包含遵守的.class /字节码文件?



是的。虽然JAR文件,只是压缩文件(你可以在你喜欢的压缩工具打开它们),这样他们就可以真正含有任何事情。



他们说的资源,有什么样的资源,我们在这里谈论什么?图片,txt文件等,或所有这些可能的?



任何类型的文件被允许在JAR。你的Java代码可以通过,例如,的的getResourceAsStream 或的的getResource 。显然,在一个JAR的.class文件被特殊处理(如字节码)。



我已经研究AWS(用于Java亚马逊Web服务API),我看到了三个.jar文件,它们分别是:AWS-Java的SDK-1.1.1.jar,AWS-Java的SDK-1.1.1-javadoc.jar,AWS-Java的SDK-1.1.1-sources.jar



以上的包装是相当普遍的。有时人们使用的.jar 作为替代文件扩展名的 .zip文件即可。我觉得这种做法混乱,但这种情况并不少见,而亚马逊已经做了在这种情况下。我认为,这种做法变得越来越常见,推出的Maven的,它存储在名为.jar文件参考源代码。



AWS-Java的SDK-1.1。 1.jar 的 - 这是必要的编译和执行的唯一文件。它包含必要的类(.class文件)和资源库的功能。



AWS-Java的SDK-1.1.1-sources.jar 的 - 这仅仅是一个包含源代码的压缩文件(的.java文件)的库。这是没有必要编译或执行。它旨在帮助您解决在使用该库时可能遇到的问题。你可以解压缩该文件,并读取你的硬盘驱动器的源代码。但是,您的IDE可以直接可能通过创建一个源代码连接主库JAR利用这个文件。有了这个库 - >源协会成立于你的IDE,IDE中就能当您使用IDE的转到定义功能对库类向您展示库的源代码。



AWS-Java的SDK-1.1.1-javadoc.jar 的 - 这仅是包含库的JavaDoc的zip文件。再次,这是没有必要编译或执行。 JavaDoc的仅仅是HTML,所以你可以直接从硬盘解压缩这个文件并读取的JavaDoc HTML。然而,大多数的IDE可以创建一个javadoc的附件主库,它允许您在IDE中拉起上下文相关的JavaDoc库。其实,大多数的IDE可以生成从-sources.jar飞的JavaDoc,所以我很少用javadoc的罐子了。



当我想导入的java库,将我总是需要进口.jar文件?



它通常被称为将JAR文件添加到类路径,但肯定的。你几乎总是需要帮助的Java找到你正在使用的所有JAR文件通过构建只要你建立或执行的类路径。一般而言,使用的JAR和类路径比.NET的DLL使用一个更手动和明确的过程。例如:Java有.NET的全局程序集缓存中没有直接等同;也香草Java将不会自动从工作目录加载.jar文件。



有创造更多的自动的感觉classpath中其他一些技术,但他们是那种先进:的Manifest.MF类路径是可能的,例如 - 但这种方法不经常使用,因为它是脆性的。从Java 6,Java有在类路径使用通配符有限的支持。



当我想导出自己的Java库,应我需要在.jar文件导出



这是标准的,是的。


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.

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.

Questions:

  1. .NET Assembly is same thing as java .jar?
  2. .dll contains compiled IL code and .jar contains complied .class/byte code files?
  3. They say resources, what kind of resources we are talking about here? Images, .txt files, etc. or all of them possible?

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

    1. aws-java-sdk-1.1.1.jar
    2. aws-java-sdk-1.1.1-javadoc.jar
    3. 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.

  1. When I want to import java libraries, will I always need to import .jar files?
  2. When I want to export my own java libraries, should I need to export in .jar file.

Thanks for help in advance.

解决方案

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

They play the same role, yes.

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

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

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

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).

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

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.

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-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-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.

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

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.

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.

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

This is standard, yes.

这篇关于.jar和.dll文件之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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