Intellij: SBT-based Scala project does not build w

2019-01-23 05:41发布

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.

4条回答
叼着烟拽天下
2楼-- · 2019-01-23 06:26
  1. Open [File -> Settings -> Build, Execution, Deployment -> Compiler]
  2. Add "--add-modules java.se.ee" to [Shared build process VM options]
查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-23 06:27

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

查看更多
疯言疯语
4楼-- · 2019-01-23 06:31

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

查看更多
贼婆χ
5楼-- · 2019-01-23 06:33

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 to Shared build process VM options

enter image description here

查看更多
登录 后发表回答