JAR 可执行文件的优缺点
我在学校的 Java 科目中一直使用 JAR 文件导出项目。我注意到它的可移植性(假设使用的计算机安装了 Java)。然而,既然如此,为什么我还没有看到开发人员使用 JAR 文件分发 Java 程序呢?使用 JAR 可执行文件的优点(除了可移植性)和缺点(除了使用 C++)是什么?
I have been using JAR files to export my projects in my Java subject at school. I noticed it's portability (assuming the computer in use has Java installed). However, with that fact, why haven't I seen developers distribute Java programs using a JAR file? What are the pros (besides portability) and cons (aside from using C++) of using the JAR executable?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题有两个组成部分。第一种是发送 JAR 且不使用安装程序。问题的第二个组成部分是部署可执行文件后在计算机上仅使用 JAR 的优缺点。我开始怀疑OP正在询问第一个组件。我的回答试图回答第二个部分。
优点
缺点
生成可执行文件的另一种替代方法是使用 JNLP。网页可以在将用户转发到 .jnlp 文件之前检查 java。
There are two components to the question. The first is shipping a JAR and using no installer. The second component to the question is the pros and cons of a using just a JAR on the machine once the executable has been deployed. I'm starting to suspect that the OP was asking about the first component. My answer tries to answer the second component.
Pros
Cons
Another alternative to producing an executable is to use JNLP. A web page can check for java before it forwards the user to the .jnlp file.
我希望优势非常明显。我遇到的最大缺点是 JAR 中未包含所需的其他依赖项。可以包含 MANIFEST 来设置类路径 - 但这要求所有依赖项都以预定义名称存在于预定义位置。这可以通过加载脚本(设置类路径等)来解决 - 此时不再将所有内容都包含在单个 JAR 中,并且大多数优点都会丢失。
I'm hoping that the advantages are pretty obvious. The biggest disadvantage I've run into is when there are additional dependencies that are required that aren't included in the JAR. A MANIFEST can be included to set the classpath - but this requires that all of the dependencies exist with pre-defined names in a pre-defined location. This can be worked-around with a loader script (to set the classpath, etc.) - at which point not everything is contained in the single JAR anymore, and most of the advantages are lost.