6

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?

Impmaster
  • 187
  • 2
  • 8
  • Is the problem that you need a program you can run by double clicking or do you need a .app? If you get the .jar to run, is that a satisfying solution? – Niklas Jan 23 '13 at 14:51
  • Actually, by now, I realized why making a .jar didn't work for me. I had in Eclipse my data folder outside of src. So now, whenever I try and run a jar, the data folder has to be in the same directory as the .jar – Impmaster Jan 25 '13 at 02:12

4 Answers4

5

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.

andrewdotn
  • 27,806
  • 6
  • 80
  • 110
0

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.

Rob
  • 10,529
  • 6
  • 34
  • 54
  • Fine. How can I make a runnable Jar in Eclipse? If I try to use the default export, I get this error: Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.library.path – Impmaster Jan 22 '13 at 19:26
  • I've been using Java on Mac for almost a decade, have never seen that. Are you building with the JRE or JDK? Which version? – Rob Jan 22 '13 at 19:27
  • Um... I don't know what those are. Also, lwjgl is a gaming library, that may be why you've never seen it? – Impmaster Jan 22 '13 at 19:30
  • @Impmaster you have to add LWJGL to your build path – tckmn Jan 22 '13 at 19:37
  • I did that in Eclipse, and in Eclipse, it works fine. But how do I LWJGL to my build path if I've already built a jar? – Impmaster Jan 22 '13 at 19:48
0

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).

Ian Roberts
  • 114,808
  • 15
  • 157
  • 175
0

When you export you must choose Runnable Jar File and then it will run when you double click it.

user2455722
  • 1
  • 1
  • 1
  • 7