Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a .jar into a Mac OS X app [closed]

I'm trying to create a java-based GUI for both Mac and windows. So far, I've been able to create an executable .jar file that runs on Windows.

The issue I'm running into is running that .jar on Mac. When I double-click to run, it says I should use -XstartOnFirstThread option to run the .jar. So, I've created a shell script that simply opens it with the following line of code:

java -XstartOnFirstThread -jar myJar.jar

This runs the program well, but it's not a solution that is easily distributable. So, I'm trying to bundle the .jar into a Mac app. So far, everything I've tried results in the same error code:

LSOpenURLsWithRole() failed for the application MyApp.app with error -10810

Here's what I've tried so far:

  • JarBundler (link here): same issue

  • Java Tutorial: tried following this tutorial, but appbundler seems not to exist anymore (at least I can't find it on my mac and I can't find it on Java's website) and most of the links to other softwares that are on this page are dead.

  • AppBundler ant task (link here): Couldn't quite firgure out how to use this.

  • Eclipse OS-X App Bundler: same issue.

  • changing permissions on the executable JavaApplicationStub within the app: same issue

  • bundling the app on my own from scratch: same issue.

I'm pretty much out of ideas at this point, is there anything I am missing?

EDIT: The .jar file that I'm using was created by Eclipse's "create runnable JAR file" export option. Not sure if this makes a different or not.

like image 306
Agastya Sharma Avatar asked Jan 29 '23 18:01

Agastya Sharma


2 Answers

I just tested this with this Mario.jar

Steps:

  1. Make sure python is installed on your mac, if not use brew and fire brew install python3
  2. git clone https://github.com/Jorl17/jar2app
  3. cd jar2app
  4. sudo ./install.sh /usr/local
  5. /usr/local/jar2app ~/Downloads/Mario.jar // replace jar path with your jar
  6. check new .app is created in the current directoty
like image 84
JTeam Avatar answered Feb 02 '23 11:02

JTeam


This is the way I used to convert a .jar (ShowTime.jar, Class ShowTime) into an .app, On MacOS Terminal:

mkdir -p package/macosx
cp ShowTime.icns package/macosx
jdk=$(/usr/libexec/java_home)
$jdk/bin/javapackager -version
$jdk/bin/javapackager -deploy -native dmg \
   -srcfiles ShowTime.jar -appclass ShowTime -name ShowTime \
   -outdir deploy -outfile ShowTime -v
cp deploy/bundles/ShowTime-1.0.dmg show-time-installer.dmg
ls -l

This is from where I take the example: How to Create a Mac OS X Installer for a Java Application

like image 38
Angel Montes de Oca Avatar answered Feb 02 '23 10:02

Angel Montes de Oca