Reputation: 3
My Program - HelloWorld.scala
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, world!")
}
}
jar cvfe HelloWorld.jar HelloWorld HelloWorld*.class
After jar file is created i tried to get the output from jar file
java -jar HelloWorld.jar
but i got the error
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$
at HelloWorld$.main(HelloWorld.scala:12)
at HelloWorld.main(HelloWorld.scala)
Caused by: java.lang.ClassNotFoundException: scala.Predef$
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
Upvotes: 0
Views: 907
Reputation: 51658
Add line
Class-Path: /home/dmitin/.m2/repository/org/scala-lang/scala-library/2.12.3/scala-library-2.12.3.jar
(i.e. your location of scala-library) to HelloWorld.jar/META-INF/MANIFEST.MF
.
Then
java -jar HelloWorld.jar Dmytro
produces
Hello, Dmytro!
Upvotes: 0
Reputation: 1341
You have to include the scala runtime and libraries into the java classpath, you can certainly do that from commandline, but I suggest you to use more comfortable tools, see for example the tutorial at www.scala-lang.org
Upvotes: 1