Getting the Garmin Connect IQ SDK to work with Java 9, 10

If you’re developing with the Connect IQ SDK and have Java 9 or 10 installed (or any version beyond Java 8), you’ll probably run into an issue like this when trying to compile your app with monkeyc or run it with monkeydo, whether from the command line or the Eclipse Plugin:

$ monkeydo myApp.prg fenix5
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
  at com.garmin.monkeybrains.prgreader.EntryPoint.parse(
  at com.garmin.monkeybrains.prgreader.EntryPoints.parse(
  at com.garmin.monkeybrains.prgreader.PrgParser.parse(
  at com.garmin.monkeybrains.monkeydodeux.MonkeyDoDeux.execute(
  at com.garmin.monkeybrains.monkeydodeux.MonkeyDoDeux.main(
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
  at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(
  at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(
  at java.base/java.lang.ClassLoader.loadClass(
  ... 5 more

This is because the monkeybrains.jar that comes with the SDK (and is used by monkeyc and monkeydo) relies on JAXB classes – specifically those from the java.xml.bind package.

Although these are still included in Java 9 and 10, they are not included on the classpath by default, because they were considered to be “Java EE” APIs. One way to get them back on the classpath is to use the --add-modules java.xml.bind command line option when invoking java.

You can fix this by modifying the monkeydo file located in your Connect IQ SDK’s bin directory, i.e. at ./connectiq-sdk-mac-3.0.1/bin/monkeydo: Find the line with the java command, comment it out, and replace with the one below.

# Push the executable to the simulator
#java -classpath "$MB_HOME"/monkeybrains.jar com.garmin.monkeybrains.monkeydodeux.MonkeyDoDeux -f "$PRG_PATH" -d $DEVICE_ID -s "$MB_HOME"/shell $TEST_FLAG $TEST_NAME

# Fix for Java 9, 10:
java --add-modules java.xml.bind -classpath "$MB_HOME"/monkeybrains.jar com.garmin.monkeybrains.monkeydodeux.MonkeyDoDeux -f "$PRG_PATH" -d $DEVICE_ID -s "$MB_HOME"/shell $TEST_FLAG $TEST_NAME

After this, monkeydo should work correctly in running your compiled app in the simulator. (Note: I did not have to make changes to the monkeyc command)

One Comment »

  1. Thank you very much !

Comments are now closed for this entry.