{"id":1773,"date":"2018-08-22T00:21:30","date_gmt":"2018-08-22T05:21:30","guid":{"rendered":"http:\/\/unitstep.net\/?p=1773"},"modified":"2018-09-02T16:26:57","modified_gmt":"2018-09-02T21:26:57","slug":"getting-the-garmin-connect-iq-sdk-to-work-with-java-9-10","status":"publish","type":"post","link":"https:\/\/unitstep.net\/blog\/2018\/08\/22\/getting-the-garmin-connect-iq-sdk-to-work-with-java-9-10\/","title":{"rendered":"Getting the Garmin Connect IQ SDK to work with Java 9, 10"},"content":{"rendered":"

If you’re developing with the Connect IQ SDK<\/a> 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<\/code> or run it with monkeydo<\/code>, whether from the command line or the Eclipse Plugin:<\/p>\n

$ monkeydo myApp.prg fenix5\nException in thread \"main\" java.lang.NoClassDefFoundError: javax\/xml\/bind\/DatatypeConverter\n  at com.garmin.monkeybrains.prgreader.EntryPoint.parse(EntryPoint.java:71)\n  at com.garmin.monkeybrains.prgreader.EntryPoints.parse(EntryPoints.java:21)\n  at com.garmin.monkeybrains.prgreader.PrgParser.parse(PrgParser.java:50)\n  at com.garmin.monkeybrains.monkeydodeux.MonkeyDoDeux.execute(MonkeyDoDeux.java:244)\n  at com.garmin.monkeybrains.monkeydodeux.MonkeyDoDeux.main(MonkeyDoDeux.java:146)\nCaused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter\n  at java.base\/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)\n  at java.base\/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)\n  at java.base\/java.lang.ClassLoader.loadClass(ClassLoader.java:499)\n  ... 5 more<\/code><\/pre>\n

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

Although these are still included in Java 9 and 10, they are not included on the classpath by default<\/a>, 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<\/code> command line option when invoking java<\/code>.<\/p>\n

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

# COMMENT THIS ONE OUT:\n# Push the executable to the simulator\n#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\n\n# USE THIS ONE INSTEAD:\n# Fix for Java 9, 10:\n# https:\/\/stackoverflow.com\/questions\/43574426\/how-to-resolve-java-lang-noclassdeffounderror-javax-xml-bind-jaxbexception-in-j\njava --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<\/code><\/pre>\n

After this, monkeydo<\/code> should work correctly in running your compiled app in the simulator. (Note: I did not have to make changes to the monkeyc<\/code> command)<\/p>","protected":false},"excerpt":{"rendered":"

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 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[64,137],"tags":[495,427,496],"_links":{"self":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts\/1773"}],"collection":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/comments?post=1773"}],"version-history":[{"count":9,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts\/1773\/revisions"}],"predecessor-version":[{"id":1799,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/posts\/1773\/revisions\/1799"}],"wp:attachment":[{"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/media?parent=1773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/categories?post=1773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unitstep.net\/wp-json\/wp\/v2\/tags?post=1773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}