如何分发Java应用程序

发布于 2024-10-18 12:22:01 字数 407 浏览 5 评论 0原文

我想了解分发 Java 应用程序的各种选项。

我知道你可以

  • 分发源代码并让用户自己编译它,或者提供 make 文件等。
  • 将其打包到 JAR 中,并具有自解压存档
  • 并且(我确信,有无数其他方式)

我希望有关最常见选项(以及我没有想到的选项)的一些解释,特别是它们是否需要用户拥有 JVM,或者可以将其与一个捆绑在一起 - 就我个人而言,我不太喜欢安装程序由于缺少 JVM 而停止。谁说应用程序需要安装程序,独立解决方案也可以。

另外,值得一问的是如何处理跨平台分发、exe 与 dmg 等...

我提出这个问题的主要动机(我欣赏的问题与其他问题类似)是找到不需要用户已经拥有的解决方案安装了 JVM - 但为了完整性,我一般性地询问。

非常感谢

I would like to know about the various options for distributing a Java application.

I know that you can

  • Distribute the Source Code and let users compile it themselves, or provide make files, etc..
  • Package it into a JAR, and have self extracting archives
  • and (I'm sure, myriad other ways)

I'm hoping for some explanations about the most common options (and one's I haven't thought of) and in particular, do they require a user to have a JVM, or can it be bundled with one - personally I'm not too fond of an installer which halts due to a lack of JVM. Who says an app needs an installer, stand-alone solutions are fine too.

Also, worth asking is how to handle cross-platform distributing, exe's vs dmg's, etc...

My primary motivation for this question (which I appreciate is similar to others) is to find solutions that don't require the user to already have a JVM installed - but for completeness, I'm asking generally.

Thanks very much

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

旧城烟雨 2024-10-25 12:22:01

分发源代码并让
用户自己编译它,或者
提供make文件等.

这对于开源项目来说可能没问题,但对于商业项目来说却很不寻常。我建议将其作为技术人员的一个选项提供,但也分发 JAR

打包成JAR

我称之为最佳实践

并且有自解压档案

制作 jar 怎么样可执行文件 代替?

希望能得到一些解释
最常见的选项(以及我的
没想到),特别是,
他们是否要求用户拥有 JVM,
或者它可以与一个捆绑在一起 -
我个人不太喜欢
安装程序因缺少而停止
JVM。

我认为捆绑 JRE 是不合法的。也就是说,很明显,如果没有 Java,基于 java 的解决方案将无法工作。如果没有安装 JRE,OpenOffice 和许多其他软件将无法安装。我想说这是可以理解的,也可以。

IzPack 似乎是创建基于 Java 的安装程序的一个很好的解决方案。

我这样做的主要动机
问题(我欣赏的是
与其他人类似)是为了找到
不需要用户的解决方案
已经安装了 JVM

正如我所写,我认为捆绑 JRE 是不合法的 [更新:它是合法的,阅读此文档以供参考](这也不是一个好的选择,因为您必须捆绑许多不同的操作系统/ 架构组合)。因此,唯一的其他方法是本机编译(抱歉,无法帮助您)。

Distribute the Source Code and let
users compile it themselves, or
provide make files, etc..

This is probably ok for open source projects, but very unusual for anything commercial. I'd recommend providing it as an option for the techies, but distributing JARs also

Package it into a JAR

I'd call this the best practice

and have self extracting archives

How about making the jar executable instead?

I'm hoping for some explanations about
the most common options (and one's I
haven't thought of) and in particular,
do they require a user to have a JVM,
or can it be bundled with one -
personally I'm not too fond of an
installer which halts due to a lack of
JVM.

I don't think it's legal to bundle JREs. That said, it's rather obvious that a java-based solution won't work without Java. OpenOffice and many others fail to install without an installed JRE. I'd say that's understandable and OK.

IzPack seems to be a good solution to create Java-based installers.

My primary motivation for this
question (which I appreciate is
similar to others) is to find
solutions that don't require the user
to already have a JVM installed

As I wrote, I think it's not legal to bundle the JRE [UPDATE: it is legal, read this document for reference] (and also not a good option, as you'd have to bundle many different OS / architecture combinations). So the only other way would be native compilation (can't help you with that, sorry).

我偏爱纯白色 2024-10-25 12:22:01

InstallBuilder 允许您轻松分发 Java 应用程序并捆绑 JVM(尽管它本身不需要 Java,所以正如您提到的那样)永远不会出现错误,因为最终用户的机器中没有 JVM)。它是一个商业产品(免责声明,我是原始开发人员),但我们为小型 ISV 提供折扣,并为开源项目提供免费许可证。 MySQL/Oracle、Jaspersoft、Alfresco、Pentaho 和许多其他带有基于 Java 工具的 ISV 都在使用它,这些应用程序已经被下载了数百万次,没有出现任何重大问题。尝试一下:)

InstallBuilder allows you to easily distribute Java applications and bundle a JVM (although itself does not require Java, so as you mention you will never get errors because the end user does not have a JVM in the machine). It is a commercial product (diclaimer, I am the original developer) but we have discounts for small ISVs and free licenses for open source projects. It is in use by MySQL/Oracle, Jaspersoft, Alfresco, Pentaho and a bunch of other ISVs with Java-based tools and those apps have been downloaded literally millions of times with no major issues. Give it a try :)

泅人 2024-10-25 12:22:01

独立应用程序

在现代 Java 中,您可以为特定主机操作系统生成带有捆绑 JVM 的独立应用程序。

有关背景信息,请阅读 Oracle 白皮书 Java 客户端路线图更新,2020-05 更新。

模块化

首先,模块化您的应用程序以支持 Java 平台模块系统。您可以通过书籍、演示视频和许多博客文章了解这一点。

模块化的好处之一是可以精简捆绑的 JDK,使其仅包含您在应用程序中实际使用的部分。这会导致使用更少的存储空间和内存。

获取 Java 实现

其次,获取其许可条款满足您的需求的 Java 实现。条款各有不同。有些是免费的,有些是商业产品。

这是我为帮助您选择而制作的流程图。

在此处输入图像描述

构建最终应用程序

第三,使用 jlinkjpackage 用于构建独立应用程序。

用于此过程的工具正在快速发展。因此,市场上可能还会有更多工具。

您捆绑的 JDK 具有针对特定主机操作系统的本机代码。因此,您需要为您选择支持的每个部署平台单独构建应用程序。

顺便说一句,请务必检查应用程序中包含的每个库的许可条款。

替代方案:GraalVM

一种提前编译的替代方法 使用 GraalVM 转换为本机代码。这是尖端技术,所以要小心,但很有前途。

Standalone app

In modern Java, you can produce a stand-alone app with a bundled JVM for a particular host OS.

For background info, read the Oracle white paper, Java Client Roadmap Update, updated 2020-05.

Modularize

First, modularize your app to support the Java Platform Module System. You can learn about this in books, presentation videos, and many blog posts.

One of the benefits of modularization is that the bundled JDK can be stripped down to include only the parts you are actually using in your app. This results in using less storage and less memory.

Obtain a Java implementation

Second, obtain an implementation of Java whose licensing terms meet your needs. Terms vary. Some are free-of-cost and some are commercial products.

Here is a flowchart I made to assist you in choosing.

enter image description here

Build the final app

Third, use tools such as jlink and jpackage to build the standalone app.

The tooling for this process is quickly evolving. So there may be additional tools coming to market.

Your bundled JDK has native code aimed at a particular host OS. So you will need to make a separate build of your app for each deployment platform you choose to support.

By the way, be sure to check the licensing terms of every library you include within your app.

Alternative: GraalVM

An alternative approach to ahead-of-time compile to native code using the GraalVM. This is bleeding-edge technology, so beware, but is quite promising.

情释 2024-10-25 12:22:01

一般来说,您有几个选择:

1) Java Web Start
2) Run it as an applet
3) download and install.

您主要对选项 3 感兴趣。您有多种安装程序(InstallJammer 是其中之一,但还有其他安装程序),您可以为其创建安装包。由于您正在考虑分发 JVM(您可以这样做),因此您正在为您的目标平台寻找不同的安装程序。

In general, you have a few options:

1) Java Web Start
2) Run it as an applet
3) download and install.

You are primarily interested in option 3. You have a variety of installers (InstallJammer is one, but you have others) that you can create installation packages for. Since you are looking at distributing the JVM (which you can do), then you are looking at different installer for every platform you are targeting.

留一抹残留的笑 2024-10-25 12:22:01

对于简单的产品,我喜欢获得一个可执行的 jar。请参阅 http://one-jar.sourceforge.net/

对于任何大型产品和安装程序都需要。 (InstallAnywhere、Install4J、LzPack 等将帮助您创建一个)

For simple products, I like to get a single executable jar. See http://one-jar.sourceforge.net/

For any big products and installer will be needed. (InstallAnywhere, Install4J, LzPack etc will help you to create one)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文