1

Does anyone know how to embed an executable jar file in a macOS Cocoa Application?

I have written the backend to a desktop application in Java and I would like to embed that within a macOS Cocoa Application so that I can write a simple UI and put the end product in the Mac App Store. The backend is very independent to where it can be a black box to the Cocoa App. All I need is for the Cocoa app to execute the jar file at certain times.

I found this question which seems to be very similar to what I am trying to do: Embedding a Java runtime into a sandboxed Cocoa Mac app but I am worried that this information may be outdated now. I would hate to go figure out how to embed the JRE and jar file only to have my application fail the App Store review. Does anyone know if Apple still allows this sort of thing? I know they have been moving away from Java as much as they can.

If this method will still work, would someone mind instructing me on how to embed the actual JRE within the Cocoa app and then how to use NSTask to launch the jar file?

Alec
  • 666
  • 8
  • 23
  • What about this https://stackoverflow.com/a/41338796/1187415 ? – Also mentioned here: https://stackoverflow.com/a/39213758/1187415 and here: https://stackoverflow.com/questions/27811043/how-to-distribute-java-application-7-0-and-above-on-mac-10-and-above. – Martin R Jul 13 '17 at 13:56
  • Well in terms of standards, I wouldn't recommend embedding any sort of executable or binary file in your project structure, unless its absolutely necessary. You could try using a config file or entitlements file. If it's possible to I'd use cocoa pods and add it to your podfile. It's not the end of the world if your app fails review. They can't see your code. They just test the application. I would recommend the solution offered here that you found https://stackoverflow.com/a/18788230/6448167 – KSigWyatt Jul 13 '17 at 13:57
  • 1
    There is no Java on a stock mac, so you definitely need to embed something. I would use JNI and treat Java like any other library (not call out to some executable) – Lou Franco Jul 13 '17 at 13:58

1 Answers1

0

You would include the jar file as a resource in the app bundle, and execute it with NSTask.

However, this is in violation of the App Store guidelines:

2.4.5 (viii) Apps should run on the currently shipping OS and may not use     
deprecated or optionally installed technologies (e.g. Java, Rosetta)

You can still distribute your app as a Developer ID Application.

alfwatt
  • 2,010
  • 2
  • 18
  • 29