Java .class文件与jar中的.java文件 [英] Java .class files vs. .java file in a jar

查看:94
本文介绍了Java .class文件与jar中的.java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你应该在.jar库中使用.class文件还是.java文件?

Should you use .class files or .java files in a .jar library?

我想拿一个我用.java文件编写的类并将它添加到jar中,以便我可以在tomcat的WEB-INF / lib目录中将其用作库。

I want to take a class that I've written in a .java file and add it to a jar so I can use it as a library in my tomcat's WEB-INF/lib directory.

我知道jar可以包含.class文件,。 java文件,或两者(或其他任何东西)。我想知道在运行时特别需要什么才能让我的jar可以被JVM读取。 这个问题的答案告诉我.class文件将工作,但.java文件也可以工作吗?

I understand that jars can contain .class files, .java files, or both (or just about anything else). I'm wondering what is specifically needed at runtime for my jar to be readable by the JVM. The answer to this question told me that .class files will work, but will .java files work as well?

我发现了很多关于如何创建jar的描述,以及关于.java文件和.class文件之间差异的大量信息。我想,我缺少的是了解JVM如何解释jar库。它们是在运行时编译的吗?

I've found many descriptions of how to create a jar, and lots of information on the differences between .java files and .class files. What I'm lacking, I guess, is an understanding of how the jar libraries are interpreted by the JVM. Are they compiled at runtime?

谢谢

推荐答案

Jar文件是编译的 java类的集合。你需要一个jar中的 .class 文件。 。 java 文件是 source 文件。

Jar files are collections of compiled java classes. You need the .class file in a jar. The .java file is you source file.

这篇关于Java .class文件与jar中的.java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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