Search code examples
javaspringmavenclassnotfoundexception

ClassNotFound exception after renaming package


I have a Spring Boot application in which I renamed package where starting class is in. Application runs without any problem when launching from IDE (Spring Tools Suite) but when I build it with maven and run from command line with

java -jar <application_name.jar>

It says that class in old_package cannot be found. Things I've tried so far:

  1. Clean project

  2. Delete metadata from workspace

  3. Copy project somewhere else and import it from there

  4. Deleting Run Configuration and creating new one with main class in new package.

I also unzipped jar located in target folder and checked its manifest file and Start-Class param is set to old package.


Solution

  • You didn't update your pom.xml, and it contains references written in the form <old_package>.MyClass, whereas this should be <new_package>.MyClass. Your IDE (I'm not an expert with STS though) uses its own rules for compilation, so your program can run in it.