I am getting "java.lang.ClassNotFoundException: com.google.gson.Gson" error even though it is defined in my classpath
In case of a JSP/Servlet webapplication, you just need to drop 3rd party JAR files in /WEB-INF/lib
folder. If the project is a Dynamic Web Project, then Eclipse will automatically take care about setting the buildpath right as well. You do not need to fiddle with Eclipse buildpath. Don't forget to undo it all.
I faced same problem and tried above solutions but none of them worked for me. Then I tried following steps and the problem was solved:
- Go to the project properties.
- Go to Java Build Path option.
- Then add
*.jar
file as external jar. - Then go to the order and export option and select the libraries and jars of the project.
- save the current changes and clean the project and run the project again.
Click on Deployment Assembly
( right above Java Build Path
that you show as active ) and make sure that you see json-lib-2.4-jdk15.jar there.
Usually, you should add it to your build path and export it from your project. Once it's exported you will see the WTP warning that it's not a part of the deployment. Choose the Quick Fix
option and add it to your deployment path.