Using a Java library in an Objective-C Mac app, an

2020-03-03 09:16发布

I've been researching this problem for a while now, and have not yet arrived at a clear answer. I am writing a Mac OSX application that I intend to eventually put on the app store, and while I will be able to write most of it in Objective-C, I do need to call methods from a library that is only available in Java. I have 2 questions:

  1. From what I have read, it seems like JNI (using the Invocation API) is the only acceptable way of doing this (even though Apple deprecated the use of Java in Mac apps, and it isn't really acceptable). Is there any other way to do this?

  2. I have read that Apple does not allow Java apps on the Mac App store, but will it allow a mostly-native app that uses JNI to incorporate some Java classes? Since JNI can be used to "package" a Java VM with the app, it seems as though Apple's cessation of including Java with OSX in the future shouldn't be an issue.

Your insight will be much appreciated. Thanks.

1条回答
放荡不羁爱自由
2楼-- · 2020-03-03 09:26

@Andrew - in a nutshell, if what you are doing is very simple (and doesn't touch libraries that use java.awt or java.swing) then GCJ /could/ work. I wouldn't recommend it at all really. The reason I say that is because GCJ doesn't support /many/ of the 'newer' java features and unless your java code is written targeting an oldish version of the JDK, you're going to run into compilation issues. If you compile with external 3rd party deps ie eclipse.anything, etc you will run into huge headaches.

I assume you have code that you have already written in java and want to leverage that code as a service to a much nicer (and native) objc UI. If that is the case, then honestly, I think you will find much more success and far less headache just biting the bullet and creating an objc codebase for your service layer :(

Of course there is the option of using the native mac ui as merely a thin client for a cloud-based distributed service layer (written in java ofc). But I'm not certain how/what apple thinks about thin clients to web based services in their app store.

查看更多
登录 后发表回答