Today, when I run the tomcat web project in intellij, tomcat fail to start up with error:
NoClassDefFoundError: xxxx
...
Caused by: ClassNotFoundException: xxxx
Steps to solve
Check artifact
First we check whether the class is in the artifact. Because intellij use artifact to build jar/war to deploy, if artifact not have this class, tomcat will certainly not find it. What should notice is that, even it compile well doesn’t mean it can run if you not include it in right classpath for ClassLoader to find.
In my case, I find the dependency of a jar file is upgraded and I didn’t update maven.
I update maven repository using the following command:
mvn clean package -U
But after update, the library in artifact is still the old version( in essence, the intellij use xml files under .idea/artifacts/
to config the artifact, and the setting is still the old version – seems a bug of intellij).
So I have to update the intellij artifact setting to make it right manually.
Check intellij target
directory
Next step, you can check whether the target directory of your project to see the output of build. If you can’t find it under target but it’s in your artifact, it may the bug of intellij and try to restart.
Check deploy directory
Finally, to check whether the jar in deploying directory are right. You may find it in the home of your tomcat.
Ref
- Differences between NoClassDefFoundError and ClassNotFoundException?
- mvn clean install vs mvn clean package
Written with StackEdit.
评论
发表评论