适用于 Mac 的 Java 应用程序

标签 java macos jar

我以前从未使用过 mac,所以我有一个关于在 mac 上运行 java 应用程序的最佳方式的问题,因为我在网上没有找到很好的答案。

所以我构建了一个 java 应用程序,并且必须将其发送到使用 mac 的客户端。我知道您可以在 mac 上使用 java -jar app.jar 从终端运行 .jar,但我想要一个客户端只能单击并可双击的图标启动程序。

我看过一些教程,其中有人制作了一个 .jar 文件,您只需双击该文件,程序就会在 macos 中启动,所以我不确定您是否可以运行 .jar 在 Macos 中只需双击即可执行?

我看到的另一个解决方案是制作一个简单的 .command 文件,该文件将使用 java -jar app.jar 运行应用程序。所以我想知道从 .jar 文件制作 mac 可执行文件的最佳方法是什么?

最佳答案

你的问题不错。

答案是“视情况而定”。 “最佳解决方案”完全有可能是简单地发送 .jar 文件以及调用它的说明。

请查看Oracle文档:

Java Documentation Section 7: Self-Contained Application Packaging

7.1 Introduction

The Java packaging tools provide built-in support for several formats of self-contained application packages. The basic package is a single folder on your hard drive that includes all application resources and the JRE. The package can be redistributed as is, or you can build an installable package (for example, EXE or DMG format.)

From the standpoint of process, producing a self-contained application package is similar to producing a basic application package as discussed in Chapter 5, "Packaging Basics," with the following differences:

Self-contained application packages must be explicitly requested by passing additional arguments to the Ant task or javapackager tool.

Operating system and tool requirements must be met to be able to build a package in a specific format.

Self-contained application packages can only be built using JDK 7 Update 6 or later.

While it is easy to create a basic self-contained application package, tailoring it to achieve the best user experience for a particular distribution method usually requires some effort and a deeper understanding of the topic.

...

7.3.5.1 OS X

The resulting package on OS X is an "application bundle".

Several configuration parameters are placed in the Info.plist file in the application bundle and must conform to the following rules:

Application ID (or main class name if ID is not specified) is used as CFBundleIdentifier.

Application version is used as CFBundleShortVersionString.

OS X 10.8 引入了 Gatekeeper,可防止执行不受信任的操作 默认代码,无论该代码是否实现于 Objective-C 或 Java。

用户可以手动启用应用程序运行,但这不是一个 完美的用户体验。为了获得最佳的用户体验,请获取 Apple 的开发者 ID 证书。 Mac 捆绑程序使用 用于签署 .app 文件夹的证书。如果您的本地用户信息 与证书的名称不同,您可能需要设置 捆绑参数 mac.signing-key-user-name,如下所示 示例:

关于适用于 Mac 的 Java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54966656/

相关文章:

xcode - 如何将两个包安装程序文件 (PKG) 合并为一个大的组合安装程序文件?

java - 无法在我的 Mac 上打开 .jar 文件

java - 是否有列出Java .jar文件支持的命令行选项的标准方法?

java - 异常 : java. lang.NoClassDefFoundError - org/json/simple/JSONValue

java - 将 JTextfield 字符串解析为整数

java - Spring - 基于 XML bean 定义更新 java 类

java - 在规划继承时,是否允许构造函数调用可重写的方法?

java - Eclipse、Maven 和代码覆盖率

python - Sublime Text 中的 f-String

java - 引用 JAR 内的文件