It\'s been too long since I\'ve last done Java, and I can\'t remember why the following happens:
Given this file, created by a standard Maven project, as can be seen her
When you attempt to execute your program, it will look for the class file using the path specified in the package. So, when you have the package statement in the file, your class file must be in the com/mycompany/app/
directory (relative to what directory you're attempting to run it from); if it can't find it, you get that exception.
Thus, when you remove that package statement, the JVM will look for it in current directory, which is why it works (because you're executing java App
in the same directory in which the App.java
and App.class
files exist).