I've tried to switch my Scala/sbt based project to Java 9. If I compile the project with sbt, it works.
If I try to build the project with the Build option of IntelliJ, I get immediately the error
Error:Module 'xyz' production: java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
I've tried to add the module as dependency
libraryDependencies += "javax.xml.bind" % "jaxb-api" % "2.3.0"
and added in the compiler settings of IntelliJ (javac as well the scala compiler)
<option name="ADDITIONAL_OPTIONS_STRING" value="--add-modules java.xml.bind" />
but does not help, unfortunately.
In addition to the above answers.
If you are not using IntelliJ and running the program from sbt console, I found the following resolved the issue:
Adding the following to your build.sbt:
libraryDependencies += "javax.xml.bind" % "jaxb-api" % "2.3.0"
Adding the import statement to your controller:
import javax.xml._
Moving this as an answer to serve as a temporary suggestion unless there is a definite solution to it and to club together few other points.
Seems like scala is not yet complete in terms of readiness to be used with JDK-9 as visible at scala/scala-dev - Support JDK 9
On the other hand, the way of solving the dependency on the
javax.xml.bind
could be currently categorized into two categories:-Your project uses a library which in turn
requires javax.xml.bind
, in which case there is not much in your hands other than waiting for that library to move to a modular structure prior to your restructuring. However, this can then be temporarily hacked by the--add-modules javax.xml.bind
option provided as the compiler argument.Your project makes use of the
javax.xml.bind
directly. In which case the ideal solution is to move away from the module and make use of the dependency[jaxb-api:2.3.0
] and refactor code accordingly.In addition to @nullpointer answer, short instruction how to use
--add-modules
Open
File
->Settings
->Build, Execution, Deployment
->Compiler
, and add--add-modules java.xml.bind
toShared build process VM options