running scala apps with java -jar
If you define -jar the -classpath is ignored:
Java manual:
-jar When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.
You can define the classpath dependencies in the Manifest metadata.
The easiest way to start your app is using the scala scripts:
scala -classpath target/scaaaaaaaaala-1.0.jar scaaalaaa.App Hello World!
Simply running
scala scaaaaaaaaala-1.0.jar
works for me with 2.11.6
use sbt-assembly
sbt plugin to produce a jar containing all dependencies
sbt-assembly github
e.g. add a line in project/plugins.sbt
:
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.10")
adjust your build.sbt
e.g. with
mainClass in (assembly) := Some("mypackage.mysubpackage.MyMainClass")
assemblyJarName in assembly := "my_assembly.jar"
then build your assembled jar with
sbt assembly
and launch it with
java -jar ./target/scala-2.12/my_assembly.jar
Et voilà, no class-path this & thats needed any more. only 1 jar.
For an executable jar, the classpath should be in the jar's manifest. For help on doing that, look through the answers to Stackoverflow: How to create an executable jar with dependancy jars.