Eclipse Gson Class Not Found

I setup a Dynamic web project in eclipse oxygen and needed Gson jar for sending out json output from my servlet for ajax response. But when I opened my url, I got an error.

NoClassDefFoundError

Java NoClassDefFoundError

These two errors are stating that the project cant load the class Gson.

java.lang.NoClassDefFoundError: com/google/gson/Gson
java.lang.ClassNotFoundException: com.google.gson.Gson

I didn't get any build errors. The code compiled correctly. That means Eclipse found the jar added in the Build Path.

I couldn't understand what the problem was. So I googled and came across Stackoverflow question describing the exact same problem. But the solutions didn't help.

I tried tinkering with the Build Path. Went down to the project properties and removed the Gson jar from the Build Path and put it back again. To see if eclipse is reading it correctly. But this didn't work either.

Solution

Finally I stumbled upon the markers in the output section. Markers showed errors for loading gson jar file in my dynamic web project.

Eclipse Markers Classpath Dependency Validator Message

The marker showed me the Classpath entry will not be exported or published.

Eclipse Classpath Entry Quick Fix

Select: Mark the associated raw classpath entry as publish/export dependency.


Mark the associated raw classpath entry as publish/export dependency

Recheck your url it will work now.

Last Updated: Sep 19, 2018


Share Tweet Share