If you're getting this error and you are using Maven to build your Jars, then there is a good chance that you simply do not have your Java classes in src/main/java/
.
In my case I created my project in Eclipse which defaults to src
(rather than src/main/java/
.
So I ended up with something like mypackage.morepackage.myclass
and a directory structure looking like src/mypackage/morepackage/myclass
, which inherently has nothing wrong. But when you run mvn clean install
it will look for src/main/java/mypackage/morepackage/myclass
. It will not find the class but it won't error either. So it will successfully build and you when you run your outputted Jar the result is:
Error: Could not find or load main class mypackage.morepackage.myclass
Because it simply never included your class in the packaged Jar.