简体   繁体   中英

Making a mac app from a jar file

I'm trying to make a Mac app (specifically a GUI) in Java. However, I'm not having much success. Here's what I've tried so far:

  1. Double-clicking the executable JAR file produced by Eclipse. RESULT: Exception thrown because the Display that I create for my app must be created on the main thread.

  2. Created my own app file that runs a Shell script that opens my JAR with the -XstartOnFirstThread command. RESULT: This was able to run on my laptop, but gave an error (-10810) when I tried running it on another Mac.

  3. Used Eclipse's Mac app bundler. RESULT: Error code -10810 on my own laptop, saying that the app could not be launched.

Based on what I've seen online, the best way to fix this is to set my JAVA_HOME and PATH variables. I'm not sure what would go in these variables, what I'd set them to, or where I'd set them. My second option would be to include a JRE within my app. However, I'm not sure what the best way to do this and I have a few questions:

  1. Why can't I use the system JRE?

  2. How do I include an JRE in an app package? Do I just include the DMG I get from Oracle?

  3. What app bundlers are out there that will do this for me? I tried to use the Eclipse app bundler, which didn't work. I also tried using Oracle's tutorial found here: http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html , but this tutorial points to an app bundler that is not available anymore.

What is the best way to resolve this issue? Any help is appreciated.

Thanks!

You have to set JAVA_HOME and PATH variables by using the given links:

https://www.mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/

http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/

In many cases, JRE already exists because it was installed when the system was configured or when another program was installed. If the system where you are installing the server or client components does not have this environment, follow the instructions to download the JRE and verify the JRE environment On Mac. Again try Eclipse app bundler (Download the latest version available and substitute the file name accordingly).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM