0

I'm trying to figure out, how I can execute Scala Code as an executable jar file.
So I've loaded a Hello World Script which just hast this code

object Main extends App {
  println("Hello, World!")
}

This is located within src\main\scala\Main.scala.
Now im running sbt package to create a jar file.
However, I'm not able to run this file, it just won't do anything.
Also, by going in the directory and running it via java -jar HelloWorld.jar is not working and I'm just getting the Error:

Error: Unable to initialize main class Main
Caused by: java.lang.NoClassDefFoundError: scala/Function0

However I have no clue why this happens and how to fix it.

Mikecraft1224
  • 99
  • 1
  • 9

1 Answers1

3

Based on the error:

Caused by: java.lang.NoClassDefFoundError: scala/Function0

I think you do not have Scala runtime libraries on the classpath.

You either need to provide a complete class-path with all libraries, or to use sbt assembly plugin to create a fat JAR.

Suma
  • 33,181
  • 16
  • 123
  • 191