question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Could not find or load main class

See original GitHub issue

I’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:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
SethTisuecommented, Jun 16, 2021

but in this issue I want to underline, that issue exists on pure scala 3 binary, not wrapped by snips sdk or any other stuff

(that would be appropriate as a comment on the other ticket)

0reactions
okarmuskcommented, Jun 16, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found