37

I made a Java application which I would like to distribute on Windows, OSX and Linux without distributing a jar file. I used the great Windows exe wrapper http://launch4j.sourceforge.net/ to create an .exe file complete with my icon that won't scare Windows users.

Are there similar wrappers that I can use for OSX/Unix? An important consideration is that I would like to have my own icon on the executable (especially for mac users).

Thanks!

Danny King
  • 1,941
  • 6
  • 24
  • 37
  • Modern tooling: [*JEP 282: jlink: The Java Linker*](https://openjdk.org/jeps/282) and [*JEP 392: Packaging Tool*](https://openjdk.org/jeps/392). Learn the [*Java Platform Module System*](https://en.wikipedia.org/wiki/Java_Platform_Module_System) – Basil Bourque Mar 30 '23 at 19:56

5 Answers5

30

Yes, on Mac OS X there is a program called Jar Bundler that is installed when you install the free (assuming that you already own a copy of Mac OS X) Xcode Developer Tools that allows you to bundle a JAR file inside a native Mac OS X "*.app" application bundle with a nice and shiny icon just like other apps.

Update
The JAR bundler doesn't exist on later versions of OS X. As a workaround, you can manually create an OS X project that invokes Java. Or, there are a variety of build system extensions that do a similar thing; for example, the gradle-macappbundle plugin for Gradle will create such a wrapper app.

Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200
  • 2
    The Jar Bundler isn't part of Xcode Develoer tools since Lion 10.8.2 (http://stackoverflow.com/questions/15375490/why-is-jar-bundler-gone-in-mac-os-x-mountain-lion-10-8-2) – gardenofwine May 17 '15 at 11:31
  • Is there a gradle way of making the windows exe installer? I.e. is there a windows analog of the macAppBundle plugin for gradle? – hepcat72 May 22 '17 at 22:09
9

JarBundler is obsolete, but there is a (better) official replacement: the javapackager tool.

For OSX, A simple, well explained, step by step tutorial on how to create a DMG from java is here: http://centerkey.com/mac/java/ . For other platforms, you just need to modify the example by using the proper switches in javapackager.

Marco
  • 423
  • 5
  • 7
  • Looks like javapackager is bundling JRE with the package. Is it possible to exclude JRE? – kaptan Mar 30 '21 at 00:04
  • I think leaving out the JRE would be a bad idea. You do not know whether the target machine has a JRE, and if it does it could be incompatible with the java version needed by the packaged java app. – Marco Apr 05 '21 at 08:36
5

If you do not have a Mac to build this on (or want to integrate it into an existing build chain), you might want to have a look at the OS X Application Bundle Plugin for Maven.

This will (if run on Linux or Windows) create a zip that will unzip as a proper Mac application. If you run Maven on a Mac, it can also make a DMG.

Thilo
  • 257,207
  • 101
  • 511
  • 656
3

Github user Jorl17 made an excellent Python script called jar2app that does this with one simple command. It even lets you customize the app icon.

https://github.com/Jorl17/jar2app

Just install it, follow the instructions, and you get the .app file.

Kiran
  • 617
  • 6
  • 20
3

You can also package your application with the JarBundler Ant task:

http://informagen.com/JarBundler

<jarbundler dir="release"
        name="MyApp"
        mainclass="org.foo.myapp.Main" 
        jar="myapp.jar" />
Emmanuel Bourg
  • 9,601
  • 3
  • 48
  • 76