My program works fine in Eclipse. However, if I try to export it as a runnable jar, the jar doesn't open when I double click it. Is there a way, in Eclipse, to export directly to a .app?
The gradle-macappbundle plugin is the easiest way I know how to do this. It hooks into your build system and generates the .app
for you.
If you want to roll your own solution, Apple’s Java Deployment Options for OS X gives you all the information you need to know about doing this. Basically a .app
is just a folder containing a JAR, with some XML files giving the classpath and so on. You can read that guide for all the details.
No. Apps contain a lot of other stuff. If you want the jar to run, you have to setup something to tell it to be opened by the JRE. Wouldn't recommend that.
There are (at least) two separate Ant tasks that can take a JAR file and associated resources and build a .app
bundle. The appbundler task from java.net produces .app
bundles that run on the Oracle Java 7 JRE and the jarbundler task produces bundles that run on the Java 6 supplied by Apple. But neither task will produce a .app
that can run on both Java 6 and 7 because Oracle (7) and Apple (6) Javas use fundamentally different APIs for spawning the JVM from the launcher stub in the .app
. If you want to be able to release your Java app to the Mac App Store then you have to use Java 7 and embed a copy of the JRE in the .app
bundle (which appbundler can do for you). Conversely, if you want your app to be runnable on Mac OS X version 10.6 or earlier then you need to use Java 6.
Your comment on one of the other answers suggests that your app requires a native library. You need to put this library inside the .app
bundle along with your JAR. The .jnilib
needs to go in Contents/Resources/Java
for a Java 6 bundle (the same place as the JAR file), for a Java 7 bundle you specify the library in the <librarypath>
fileset and it will be copied to the right place by appbundler (Contents/MacOS
).
When you export you must choose Runnable Jar File and then it will run when you double click it.
© 2022 - 2024 — McMap. All rights reserved.