Could not find or load main class
See original GitHub issueI’m not sure but I found unexpected behavior after compilation Scala 3
code with SBT
.
build.sbt
looks like:
name := "scala-cheat-sheet"
version := "1.0"
scalaVersion := "3.0.0"
Compile/mainClass := Some("com.okarmusk.Main")
The main object is located under src/main/scala/com/okarmusk
and looks like:
package com.okarmusk
object Main {
def main(args: Array[String]): Unit = {
println("Hello world!")
}
}
I sequentially run commands:
sbt clean
sbt package
scala target/scala-3.0.0/scala-cheat-sheet_3-1.0.jar
As the result I obtained:
Error: Could not find or load main class target.scala-3.0.0.scala-cheat-sheet_3-1.0.jar
Caused by: java.lang.ClassNotFoundException: target.scala-3.0.0.scala-cheat-sheet_3-1.0.jar
Problem exists on scala 3 version Scala code runner version 3.0.1-RC1 -- Copyright 2002-2021, LAMP/EPFL
, on scala 2 example works as expected.
OS: xubuntu 20.04 sbt: 1.5.2 scala: 3.0.1 RC
Issue exists also in official scala 3.0.0 version
It is worth to notice that when I run sbt run
the program executes correctly.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Java Guide: How to Fix "Could not find or load main class"
The Java “Could not find or load main class” error is thrown when the JVM fails to find or load the main class...
Read more >java - What does "Could not find or load main class" mean?
When you get the message "Could not find or load main class ...", that means that the first step has failed. The java...
Read more >Java – “Could Not Find or Load Main Class” Error | Baeldung
And it failed with the error “Could not find or load main class helloworld.” As discussed earlier, the compiler will generate the .class...
Read more >Error: Could not find or load main class in Java [Solved]
If you are getting "Error: Could not find or load main class XXX", where XXX is the name of your main class while...
Read more >Could Not Find or Load Main Class in Java - Javatpoint
The class has been declared in the wrong package. · Dependencies missing from the CLASSPATH. · The subdirectory path doesn't match the fully...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
(that would be appropriate as a comment on the other ticket)
I’ve created issue on
sbt
repo and it was redirect as scala 3 issue. For more information, please check #6541. I’ve been terrified when I saw such kind of error, especially when I switched back to scala 2 and everything works.