简体   繁体   English

如何制作不需要安装Java的Mac App Java

[英]How to make Java Mac App that doesn't require installing Java

I want to make a Mac Application using Java code I wrote, and I want to make it that the person using it doesn't require Java to be installed on their own computer.我想使用我编写的 Java 代码制作一个 Mac 应用程序,并且我想让使用它的人不需要在他们自己的计算机上安装 Java。

Is there a way to create a Mac Application so it can run on any mac, whether they have Java installed or not?有没有办法创建一个 Mac 应用程序,以便它可以在任何 Mac 上运行,无论它们是否安装了 Java?

Either bundle a JVM or compile native捆绑 JVM 或编译本机

You have a choice of three ways to deliver a local Java-based app to a Mac user.您可以选择三种方式将基于 Java 的本地应用程序交付给 Mac 用户。

  • User installs a JDK or JRE on their machine.用户在他们的机器上安装JDKJRE (Or IT sysadmin person does so.) (或者 IT 系统管理员这样做。)
  • App comes bundled with a JVM for a specific OS and specific chip architecture.应用程序与特定操作系统和特定芯片架构的JVM捆绑在一起。
  • App is compiled to native code for a specific OS and specific chip architecture.应用程序被编译为特定操作系统和特定芯片架构的本机代码。

Install JDK/JRE安装 JDK/JRE

In a controlled environment such as a corporation or school, it may be practical to install a JDK or JRE on every Mac.在公司或学校等受控环境中,在每台 Mac 上安装 JDK 或 JRE 可能是可行的。 If you are writing JavaFX apps, you could install an edition of a JDK/JRE that comes with the OpenJFX libraries.如果您正在编写JavaFX应用程序,则可以安装 OpenJFX 库附带的 JDK/JRE 版本。

Your Java app can then execute by using the already-installed JVM.然后可以使用已安装的 JVM 执行您的 Java 应用程序。

By the way, in such a controlled environment, OpenWebStart is a way to deliver and launch a local Java app by using the convenience of a web browser.顺便说一句,在这样的受控环境中, OpenWebStart是一种通过使用 web 浏览器的便利来交付和启动本地 Java 应用程序的方法。

In contrast, Oracle has abandoned the approach of expecting common consumer machines to come equipped with Java pre-installed.相比之下,Oracle 已经放弃了期望普通消费机器预装 Java 的方法。 For details, see the Oracle white paper, Java Client Roadmap Update .有关详细信息,请参阅 Oracle 白皮书, Java 客户端路线图更新 So expecting individuals to have Java installed is not practical.因此,期望个人安装 Java 是不切实际的。

Bundle JDK/JRE捆绑 JDK/JRE

You can build your app in such a way as to include a JDK/JRE for a specific kind of machine, meaning a specific operating system and a specific chip architecture.您可以构建您的应用程序,以包含适用于特定类型机器的 JDK/JRE,这意味着特定的操作系统和特定的芯片架构。

For Macs, that means you need one build for Macs with Intel (x86) chips, and another build for Macs with Apple Silicon (ARM, AArch64) chips.对于 Mac,这意味着您需要一个构建用于配备Intel (x86)芯片的 Mac,另一个构建用于配备Apple Silicon (ARM、AArch64)芯片的 Mac。 You would need to to either supply two separate versions of your app, one for each child, or perhaps a “fat binary” that includes two JDKs/JREs for both chips.您可能需要为您的应用程序提供两个单独的版本,每个子版本一个,或者可能需要为两个芯片提供一个包含两个 JDK/JRE 的“胖二进制文件” The fat binary approach was supported by Apple (and its originator, NeXT Inc. ) in previous chip transitions, but I've not verified is this is the case now in the Intel to Apple Silicon transition.在以前的芯片转换中,Apple(及其发起者NeXT Inc. )支持胖二进制方法,但我尚未验证现在英特尔到 Apple Silicon 的转换是否就是这种情况。

Modern tooling helps with embedding a JDK/JRE.现代工具有助于嵌入 JDK/JRE。 See jlink and jpackage .请参阅jlinkjpackage See Packaging Tool User's Guide .请参阅打包工具用户指南 As of Java 9, the Java Platform Module System enables including only the parts of the JDK/JRE actually used by your particular app.从 Java 9 开始, Java 平台模块系统仅允许包含特定应用程序实际使用的 JDK/JRE 部分。 Unused parts are omitted, making for a smaller-sized final app artifact.省略了未使用的部分,使最终的应用程序工件尺寸更小。

Compile native编译本机

The last way uses GraalVM technology to compile your code to native code specific to the targeted runtime machine.最后一种方法使用GraalVM技术将您的代码编译为特定于目标运行时机器的本机代码。 Instead of compiling to bytecode for a conventional JVM to interpret and optionally JIT-compile at runtime, full compilation to native machine language is performed when you build your app.与传统的 JVM 编译为字节码以在运行时进行解释和可选的 JIT 编译不同,在构建应用程序时会执行对本机机器语言的完整编译。 This approach is cutting-edge, perhaps bleeding-edge.这种方法是前沿的,也许是前沿的。 So research carefully and test thoroughly if you dare to consider this novel approach.因此,如果您敢于考虑这种新颖的方法,请仔细研究并彻底测试。

With both of the last two approaches, you have the option of distributing through the Apple App Store .使用最后两种方法,您可以选择通过Apple App Store进行分发。

You don't need JDK to install on the client machine but as we know java converts the program into bytecode and a java compiler is needed to compile that bytecode into machine language you must install JRE on the client computer whether it is mac or windows or any other operating system您不需要在客户端计算机上安装 JDK,但我们知道 java 将程序转换为字节码,需要 java 编译器将该字节码编译为机器语言 您必须在客户端计算机上安装 JRE,无论是 mac 还是 windows 或任何其他操作系统

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM