Question

I am currently teaching a student on how to code a game in Java on a Mac. GameCenter is a service provided by Apple that lets one see their game stats on a leaderboard and lets them play online. Does anyone know if it's possible to implement GameCenter in Java or if it's even possible to publish a Java app on the Mac App Store?

Was it helpful?

Solution

The Basics

You would need to translate parts of your Java application over to Objective-C, which is what OS X and iOS support.

Fortunately in the last couple of years there has been a decent amount of progress and attention in terms of tools, techniques, and methods that can help you do this. There's even an open-source tool/runtime that can take Java code and turn it into Objective-C:

J2ObjC

It's fairly popular, and can probably set you in the right direction.


EDIT: I've added the word parts above since it was apparently unclear to Basil Bourque, and/or possibly anyone else who may have taken the word translate as having to re-write your entire app in objective-c.

OTHER TIPS

Java-Based Mac App

The answer by l'L'l is not entirely correct. You do not need to translate your Java code to Objective-C. You can ship a Java-based app in the Apple Mac App Store.

Apple changed their policies to now allow Java-based apps for sale in the Mac App Store. This applies only to Mac apps, as far as I know, not for iOS. There is no Java implementation released that runs on iOS as far as I know. Sun demonstrated a prototype once publicly, but never released anything for iOS afaik.

See my answer to a similar question. The successful app Moneydance is an example, as noted on this answer.

Nutshell

  • You create a thin Objective-C app that wraps your Java app, using Xcode.
    Other people have provided templates for this minimal code.
  • Your Mac app must include a JVM (Java Virtual Machine).
    In other words, your Mac app cannot access a JVM that may already be installed on the user’s Mac.
  • You may use Swing or JavaFX for presenting a user interface.
    Both Apple’s and Oracle’s implementations of Java ship with extensions to Swing for a Mac look and feel. The latest implementations from Oracle also include JavaFX.

Oracle provides these instructions on how to package your app for the Mac App Store.

GameCenter

I do not know the details of accessing GameCenter from the Java-based part of your game. You may need to write some Objective-C in order to interact with Apple's GameCenter libraries/framework.

As noted by MadProgrammer (comment on question), your Java code may interact with Objective-C code by using either:


Xojo

By the way, another non-Objective-C platform for shipping apps in the Mac App Store is Xojo, formerly known as RealBasic. A very slick set of tools with a fully object-oriented programming language. Popular with both beginning programmers and professionals.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top