I created a multi-project build in sbt. Here's build.sbt in the main directory:
lazy val root = project in file(".") aggregate(data, reco, result)
lazy val data = project dependsOn(common)
lazy val reco = project
lazy val result = project dependsOn(common)
lazy val common = project
When I use package
or one-jar
command, the classes and resources in common
project are not packaged into data
or result
jars. So when I run the generated jar by
java -jar data_2.10-1.0-onejar.jar
it leads to NoClassDefFoundError as a consequence.
So could anyone help me deal with such problem? Thanks in advance.
Typically, if a key has no associated value in a more-specific scope, sbt will try to get a value from a more general scope, such as the ThisBuild scope. This feature allows you to set a value once in a more general scope, allowing multiple more-specific scopes to inherit the value.
Your dependent projects are not exporting Jars (producing classes only). Put the following line in the build.sbt of all dependent projects (including your current project too, if necessary):
exportJars := true
That should fix it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With