Search code examples
javaeclipsespring-mvcclassnotfoundexception

Spring MVC helloworld - Package name cannot start with java?


Open Eclipse --> New Project --> Spring Project --> Spring MVC Project -->

After giving the name of project give the package name as java.example.com ( where it shows com.myexample.myapp* )

When you will start the Tomcat Server you will see ClassNotFoundException as then Spring MVC cannot read the Controller HelloController.

I m not able to figure out the root cause but if my package name doesn't start with java everything works fine.


Solution

  • The java package is reserved for Java runtime classes. For security reasons, you are not allowed to create your own classes with that name.

    See https://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#jls-6.1.

    Names of packages intended only for local use should have a first identifier that begins with a lowercase letter, but that first identifier specifically should not be the identifier java; package names that start with the identifier java are reserved for package of the Java SE platform.