Error: Could not find or load main class Caused by: java.lang.ClassNotFoundException

Hi all,
I’m stuck with this problem since several days, trying a lot of solutions such as reinstalling IntelliJIdea, sbt, scala, trying several versions of java.

After packaging a project with >sbt compile and >sbt package, I can’t make the produced jar file executed, I got this error:
Error: Could not find or load main class rockjvm_2.13-0.1.jar
Caused by: java.lang.ClassNotFoundException: rockjvm_2.13-0.1.jar

My project structure is on the pictureRockjvm_00


So I created a package named example within which I create an object named Playground. (sbt 1.5.5., Scala 2.13.7, IntelliJ IDEA 2021, openJDK 15.0).

Once packaged, I got the jar and wherever I install it and launch with >scala rockjvm_2.13-0.1.jar, I got those errors.

Could I have your help please,
Thank you very much,
Best regards

What does your build.sbt look like? This looks like you are downloading a local copy of rockjvm, which is an unusual way to build a Scala project…

From the error message I would suppose you have set the main class of your jar to be “rockjvm_2.13-0.1.jar” ?

Do you have a setting in your build.sbt for Compile / mainClass := Some("rockjvm_2.13-0.1.jar") perhaps?

1 Like

Thank you for the response.
Maybe my problem comes from a wrong installation/configuration since I didn’t get those errors on a different computer. I’ll investigate this later.
Thank you very much,
Best regards