How Fix ClassNotFoundException and HTTP Status 404 in Eclipse
- Details
- Written by Nam Ha Minh
- Last Updated on 28 October 2023   |   Print Email
When developing Java web applications using Eclipse IDE and Apache Tomcat server, there are two annoying errors that make programmers’ headache - they are: ClassNotFoundException and HTTP Status 404 Not Found. No matter how hard you try, these kind of error are not resolved. The good news is that, in this post I’d like to share a solution which you might not think of, or have not tried it yet.
1. How to Fix ClassNotFoundException Error
This exception causes HTTP Status 500 Internal Error, saying that a required class is missing. For example, you may see this in Eclipse’s console:
You try to add the library that contain the required class into the project’s classpath. It’s present but the error still persists. So what really gets wrong?
I suggest you check the project properties dialog, and go to the Web Deployment Assembly configuration, as shown below:
Click Add button, then choose Java Build Path Entries:
Click Next, then select Maven Dependencies or other Java libraries used by the project (if Maven is not used):
Click Finish, and you should see Maven Dependencies will be copied to the deploy path WEB-INF/lib, as shown below:
Now click Apply and Close. Tomcat will be restarted and you can test your application again. The ClassNotFoundException error will be resolved.
That means, somehow the Web Deployment Assembly configuration is flawed, causing dependencies not copied to WEB-INF/lib folder on Tomcat. That’s why you get ClassNotFoundException.
2. How to Fix HTTP Status 404 Not Found Error
In a similar fashion, you may get HTTP status 404 Not Found error due to misconfiguration in the Web Deployment Assembly of your project:
To fix this error, go to project’s properties dialog. Go to Web Deployment Assembly. Click Add and choose Folder:
Click Next, then choose WebContent or the directory contains web files, e.g. src/main/webapp:
Then click Finish. You should see the /WebContent or /src/main/webapp entry is added to the deploy path / (context root) of the application, as shown below:
Click Apply and Close. Tomcat will be restarted and you can test again. The HTTP status 400 Not Found error is resolved.
That means somehow the Web Deployment Assembly configuration is flawed, causing web files (HTML, JS, CSS, images…) are not deployed - That’s why you got HTTP status 404 Not Found error.
Watch the following video to see how I do the steps to solve HTTP status 404 Not Found error in action:
Other Error Fixes you may find helpful:
- [Solved] Tomcat Error HTTP Status 404 Not Found
- [Eclipse] How to Fix Error: project description file (.project) for … is missing
- [Fixed] No Persistence provider for EntityManager named XXX
Other Eclipse Tutorials:
- How to import existing projects into Eclipse workspace
- How to create, deploy and run Java Servlet in Eclipse
- How to generate JAR file in Eclipse
- How to create WAR file for Java web application in Eclipse
- How to create Ant build file for existing Java project in Eclipse
- How to generate Javadoc in Eclipse
- How to create Java web project with Maven in Eclipse
- 25 Eclipse Shortcut Keys for Code Editing
- How to Add Copyright License Header for Java Source Files in Eclipse
- How to monitor HTTP requests and responses using TCP/IP Monitor in Eclipse
Comments