Search code examples
javamavenclassnotfoundexception

Error java.lang.ClassNotFoundException in tests after execute mvn clean:install


In my console execute mvn clean:install -Dmaven.test.skip=true and my project runs okay.

But if I try to write a new test or run an existent one, I get java.lang.ClassNotFoundException.

To fix it in Eclipse I must right click in my project -> properties -> Java compiler -> Compiler compliance level and there change the Java version so the .class files get generated again.

--EDIT.--

Thank you for your attention, my question is, how to recreate the classes again so i can run my tests without the right click -> etc -> etc.

And yes, it is mvn clean install not mvn clean:install


Solution

  • Basically, maven clears all compiled class files. So, you get java.lang.ClassNotFoundException and other missing class errors. To fix,
    In your Eclipse, right-click on project, Maven - Update Project...
    Click OK and wait until maven compiles you Java project again.

    enter image description here