Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij: SBT-based Scala project does not build with Java 9

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.

like image 341
Marco Avatar asked Sep 23 '17 15:09

Marco


People also ask

Which Scala version does sbt use?

We recommend that you upgrade to sbt versions 1.0 and later which are compatible with the Scala version 2.12 (requires Java 8).

How compile sbt project in IntelliJ?

Press Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.

Does IntelliJ work with Scala?

To start working with Scala in IntelliJ IDEA you need to download and enable the Scala plugin. If you run IntelliJ IDEA for the first time, you can install the Scala plugin when IntelliJ IDEA suggests downloading featured plugins. Otherwise, you can use the Settings | Plugins page for the installation.

How do I switch between Scala versions?

You can temporarily switch to another version of Scala using ++<version> . This version does not have to be listed in your build. scala. versions property, but it does have to be in a repository or be a local Scala version you have defined.


1 Answers

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._

like image 133
Pablo Rengifo Avatar answered Oct 13 '22 06:10

Pablo Rengifo