Run compiled scala 3 code give java.lang.NoClassDefFoundError: scala/util/CommandLineParser$ParseError

Viewed 286

it may be a silly question from a scala newbie like myself.

I created the simple hello.scala using scala 3 syntax as follow:

@main def hello: Unit = 
  println("Hello world!")
  println(msg)

def msg = "I was compiled by Scala 3. :)"

Then, compile the code using this command $scala3-compiler hello.scala. This give me the .class stuff

>hello.class  
>Hello$package.class  
>hello.tasty  
>Hello$package.tasty  
>Hello$package$.class  

Finally, I try to run this compiled files using $java -cp . hello which results in the error as follow:

Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: scala/util/CommandLineParser$ParseError

How can I run this compiled files using java? It seems that the class CommandLineParser$ParseError is missing, but if I create the new project using $sbt new scala/scala3.g8 then $sbt run
it can be run just fine. I wonder why.

P.S. I installed the scala using coursier which give me 2 versions of scala. If I typed $scala --version it returns the 2.13.6 scala versions.

0 Answers
Related