Questions regarding sbt, ClassNotFoundExceptions and Eclipse

Moderatoren: pmueller, SE - Design and Construction

Ben Kohr
Beiträge: 34
Registriert: 14. Apr 2015 17:41

Questions regarding sbt, ClassNotFoundExceptions and Eclipse

Beitrag von Ben Kohr »


while working on task 1, I wrote a test class "MyClass", inserted a main method and let it implement the ILogger interface (I did this all via Eclipse). When I tried to start the program via Eclipse, it told me that the main class "ex01.task1.MyClass" was not found, even if this class existed and was in that package.
Via "sbt run" in the console, I could run the program (after setting the main compile path in the build.sbt file) successfully, but still not with eclipse. Afterwards I closed the console, opened it again and tried to run the program again with "sbt run". An error occurred with a "ClassNotFoundException", which appeard again when tried again. When I rename the class via Eclipse's refactoring functionality and change the name in the build.sbt file accordingly, I can successfully execute the program (until closing the console and opening it again). For now, I uploaded a solution that worked when tried last time (with a changed build.sbt and the MyClass class).

I have the following questions regarding this:
1. What could be a reason for Eclipse not finding the main class even if it exists in tha specific package structure? I already installed the required plugin in Eclipse für sbt.
2. What could be a reason for "sbt run"'s strange behavior (working correctly, then giving an error)?
3. Are there any configurations etc. I have to make in order to help my application to run stable (without an appaering ClassNotFoundException)?
4. Is it okay to have uploaded the MyClass class and the changed build.sbt file?


Beiträge: 179
Registriert: 15. Apr 2015 18:24

Re: Questions regarding sbt, ClassNotFoundExceptions and Eclipse

Beitrag von 0b101101101 »

In another thread it was mentioned not to change the build.sbt, because it will not be uploaded and for testing they will just use the default build.sbt. I believe the reason for this is, so you cannot add arbitrary libraries in the build.sbt but only use the provided ones. So I dont think uploading with a changed build.sbt is sensible... :)

If you get strange behaviors try to tell eclipse to "clean project" and write "sbt clean" and try again. If the errors are still there, maybe you could provide additional information on how to reproduce the error?

By the way, instead of setting a main class in sbt, you can also use "sbt runMain" instead of "sbt run".

Beiträge: 448
Registriert: 25. Sep 2007 12:12

Re: Questions regarding sbt, ClassNotFoundExceptions and Eclipse

Beitrag von eichberg »

HI, as already stated - it is highly recommended and generally also not required to make changes to build.sbt. Things that may help are:
- close eclipse (to be precise: close Scala IDE - I highly recommend that you use the preconfigured Scala IDE and do not install the plugins on top of a regular Eclipse installation)
- run sbt clean test:compile eclipse
- restart eclipse
- refresh the project (right click on the project as a whole -> refresh)
- if it still doesn't work, "clean and build the project"

If this doesn't work, then I really have to recommend to use IntelliJ or use Atom/VSCode (with Ensime Plugin) or...


Zurück zu „Software Engineering - Design and Construction“