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:

ClassNotFoundException error

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:

deployment assembly dependency missing

Click Add button, then choose Java Build Path Entries:

choose Java Build Path Entries



Click Next, then select Maven Dependencies or other Java libraries used by the project (if Maven is not used):

choose Maven Dependencies

Click Finish, and you should see Maven Dependencies will be copied to the deploy path WEB-INF/lib, as shown below:

maven dependencies added

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:

http status 404 not found

To fix this error, go to project’s properties dialog. Go to Web Deployment Assembly. Click Add and choose Folder:

choose Folder in deployment assembly

Click Next, then choose WebContent or the directory contains web files, e.g. src/main/webapp:

Choose WebContent in deployment assembly

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:

WebContent added

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:

 

Other Eclipse Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on Facebook and watch his Java videos you YouTube.



Add comment