Using a bundled JRE on OSX

后端 未结 5 664
面向向阳花
面向向阳花 2020-12-28 17:55

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

相关标签:
5条回答
  • 2020-12-28 18:37

    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.

    0 讨论(0)
  • 2020-12-28 18:41

    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 JRE

    • You 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 like jre

    • 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 named applicationname).

    • 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

    0 讨论(0)
  • 2020-12-28 18:50

    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.

    0 讨论(0)
  • 2020-12-28 18:53

    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.

    0 讨论(0)
  • 2020-12-28 19:00

    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

    0 讨论(0)
提交回复
热议问题