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.
Is there a way to create a Mac Application so it can run on any mac, whether they have Java installed or not?
CodePudding user response:
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
CodePudding user response:
You have a choice of three ways to deliver a local Java-based app to a Mac user.
- User installs a JDK or JRE.
- App comes bundled with a JVM for a specific OS and specific chip architecture.
- App comes compiled to native code for a specific OS and specific chip architecture.
In a controlled environment such as a corporation or school, it may be practical to install a JDK or JRE on every Mac. If you are writing JavaFX apps, you could install an edition of a JDK/JRE that comes with the OpenJFX libraries. In contrast, Oracle has abandoned the approach of expecting common consumer machines come equipped with Java pre-installed. So expecting individuals to have Java installed is not practical.
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. 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. 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. The fat binary approach was supported by Apple (and its predecessor, NeXT Computer) in previous chip transitions, but I’ve not verified is this is he case now in the Intel to Apple Silicon transition.
Modern tooling helps with embedding a JDK/JRE. See jlink and jpackage. As of Java 9, the Java Platform Module System enables including only the parts of the JDK/JRE actually used by your particular app. unused parts are omitted from inclusion, making for smaller-sized final app artifact.
The last way uses GraalVM technology to compile your code to native code specific to the targeted runtime machine. Instead of compiling to bytecode for a conventional JVM to interpret and optionally compile at runtime, full compilation to native machine language is performed when you build your app. This approach is cutting-edge, perhaps bleeding-edge. So research carefully and test thoroughly if you dare to consider this novel approach.