How can I build a Mac OS X .app from an eclipse program
Asked Answered
S

4

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?

Seeseebeck answered 22/1, 2013 at 19:22 Comment(2)
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?Rightminded
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 .jarSeeseebeck
O
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.

Overture answered 22/1, 2013 at 19:29 Comment(0)
U
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.

Undoubted answered 22/1, 2013 at 19:25 Comment(5)
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.pathSeeseebeck
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?Undoubted
Um... I don't know what those are. Also, lwjgl is a gaming library, that may be why you've never seen it?Seeseebeck
@Seeseebeck you have to add LWJGL to your build pathBartels
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?Seeseebeck
F
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).

Forefront answered 22/1, 2013 at 20:16 Comment(0)
B
0

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

Bartolomeo answered 10/11, 2013 at 20:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.