For some time now, our Java application has came pre bundled with a JRE on Windows. We have a little launcher app written in C that make the application use our pre bundled JRE. Now with Apple's crusade to slowly kill Java we have decided that it would be prudent to something similar on OSX. What would be the best way to use a pre bundled JRE on OSX?
-
Apple does not want to kill Java on Mac OS X but will use a standard Oracle JVM instead of its own version. – Matteo Jul 09 '12 at 05:13
-
Are you saying I could bundle a JRE from oracle, and use that one on a Mac Java app? – Mike2012 Jul 09 '12 at 23:29
-
You could but I don't see why you should bundle a JVM with your app. You will have to keep it updated especially for security updates. I would never trust a bundled JVM. I am just saying that Apple did not abandon Java just decided not to build its own and use the one by Oracle. – Matteo Jul 10 '12 at 05:33
-
Well Apple has also decided to stop bundling any version of Java with the operating system. As of lion users would need to download Java before a Java application will work. – Mike2012 Jul 10 '12 at 16:31
-
Sure but would you trust an official version from Oracle or a JVM bundled with an application? How can I check if the bundled version is correct? If all the security patches were updated? – Matteo Jul 10 '12 at 18:53
-
1@Matteo: the most important reason for bundling an own JRE is to provide the user an all-inclusive package. They just need to download and start it. No need to download and install any other application or framework before. A second reason is that the application developer knows which version they shipped, so their support effort will be much less. – Mot Jul 14 '12 at 13:17
-
1@Matteo There have been some recent very good examples of why you should bundle a JRE rather than pick up a system one. In Java 7 Oracle changed the default sorting algorithm to throw an exception if the comparator wasn't transitive. Regardless of whether you think that functionality is important or not there are any number of ways they could have implemented that such that it didn't break existing code. Net result is that you can't trust Oracle to provide you with a stable environment in the form of a system wide JRE. – AntonyM Jul 15 '12 at 10:46
-
1@Matteo if you run Java applications directly on a computer, Windows, Linux or OS X, you do not have any security active. The application can do anything you can do with other programs, so instead of worrying about the bundled JVM you should worry about the whole application (since that most likely is the only thing that will be run by that JVM). – Thorbjørn Ravn Andersen Jul 22 '13 at 20:34
5 Answers
I'm the author of the blog post linked by @Daniel in his answer. I successfully bundled the OpenJDK and published a Java app on the Mac App Store.
First, let me correct some issues in the accepted answer.
- It is perfectly legal to bundle the OpenJDK and to redistribute it.
- The OpenJDK doesn't run only on Lion, I used it on pre-Lion up to Mountain Lion. It needs to be patched to work on a 32 bit OS though.
- The OpenJDK is in beta quality but it's still acceptable to run a complex Swing application. There are a few issues on OSX, but I described how to fix them in this post.
There's no need to create any script as described in @Matteo's answer, you can use an application called AppBundler, published by Oracle, to create the native executable that will launch your application and create a native bundle. AppBundler will also generate a Info.plist file that contains info on how to launch your application, like the name of the executable to launch, Java arguments etc...
From 10.7.5 and above your app has to be Gatekeeper compatible and signed (so you must enroll in the paid Mac developer program) if you don't want a dialog saying that your app is from an unidentified developer to appear when the user first opens it.
To be deployed on the App Store your app also has to be able to work in a sandboxed environment but it's not a strict requirement if you distribute it outside the App Store.
Note that AppBundler lack some useful features, you may be interested in this fork.

- 3,535
- 2
- 25
- 25
-
This answer or @Daniel's answer should be the accepted answer. They answer the question precisely, completely, and with authoritative information directly from Oracle. – Jason Aug 10 '15 at 14:29
Even if I find it a bad idea (see below) you could just bundle a JVM like OpenJDK and then start your application with a small script calling your java
executable.
Notice: I have no idea if redistributing a JVM is allowed (legal), you should check the agreement before downloading
The first problem you will have is that at the moment there is just Apple's version or Oracle Java 7u6 Mac OS X Port Developer Preview Release (which is just a preview). (e.g., http://jdk7.java.net/macportpreview/). This will change in the future when Apple will stop supplying its own version. So at the moment you are stuck with a preview running on Lion only. But I will show you an example.
Download the installer, mount the disk image, right click on the plugin, choose "Show package content" extract the
Home
folder, it contains the JREYou can then check with
$ ./Home/bin/java java version "1.7.0_06-ea" Java(TM) SE Runtime Environment (build 1.7.0_06-ea-b18) Java HotSpot(TM) 64-Bit Server VM (build 23.2-b08, mixed mode)
I would then rename
Home
in something likejre
If you package this folder with your application you will just have to include a small script with
#!/bin/sh ./jre/bin/java -classpath myniceapplication.jar
To be able to build an application you will need an
applicationname.app/Contents/MacOS
folder containing you script (which should be namedapplicationname
).Now it seems that you need the use absolute paths in these scripts
/Path/applicationname.app/Contents/MacOS/jre/bin/java -classpath myniceapplication.jar
I suppose that there is a better solution to build a Mac OS X application bundle but I'm not an expert. This example was just to show that it can work.
Summarizing:
Check if it is allowed to redistribute the JRE (and check which are the conditions)
I would not do it since you will have to keep it updated and update your application every time there is JRE security update
As a user I would trust more Oracle than a random developer (nothing personal :-) to get a JRE

- 14,696
- 9
- 68
- 106
-
When having mounted the `jdk-7u5-macosx-x64.dmg` from Oracle, I'm not sure where to find the plugin to right-click (without installing), because it only contains a `JDK 7 Update 05.pkg` and when I right-click it, there is no "Show package content" menu item. – Mot Jul 14 '12 at 14:07
-
No, OpenJDK does not contain a pre-build copy (you have to build it as far as I remember). The link in my answer points to the Java Plugin which contains a copy of the JRE (http://www.java.net/download/jdk7u6/archive/b19/binaries/JavaAppletPlugin.dmg) – Matteo Jul 15 '12 at 12:24
-
Your link points to a preview build. I was referring to the JDK which one can download from the [standard Oracle website](http://www.oracle.com/technetwork/java/javase/downloads/index.html). A JRE like for the other platforms currently is not available for OSX. – Mot Jul 16 '12 at 05:59
-
@MikeL. Yes as I said at the moment there is *no* JDK 1.7 for Mac. I will come but it not yet available. You can just use OpenJDK which is a preview. If you want a stable and finished JDK 1.7 you will have to wait. – Matteo Jul 16 '12 at 11:55
There are some detailed instructions in this blog post about bundling a JRE in your app, and enabling it to be submitted to the App Store.

- 10,115
- 3
- 44
- 62
Here is a step-by-step guide from Oracle themselves on how to bundle a JRE for distributing on Apple: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html

- 2,418
- 1
- 29
- 41
-
This answer or @Marco's answer should be the accepted answer. These are the steps directly from Oracle on how to bundle a Java application for the Mac and Mac App Store. – Jason Aug 10 '15 at 14:28
While this reply is long after the initial question if may be of interest to others still searching for an answer.
I am on the development team of a small application called Pyxis Bundler that can bundle applications for OSX where the user can choose to include the JRE from their CLASSPATH, can select a specific JRE or none.
This application will generate a properly structured Mac Application Bundle, including icon and splash, and the user can even write the version number to the splash screen. In addition it can create a multi-resolution Apple Icon Image from a PNG file (to use as a modern ICNS file).
This is an easy to use GUI application where settings are automatically saved, making it easy to update applications.
The only prerequisite is that the developer uses proper package names. Single word package names are not allowed.
More information is available from https://explorepyxis.com
A free trial is available. Please drop an email to the company to request same.

- 1
- 2