[JAVA] [Servlet / Ajax] How to resolve NoClassDefFoundError [Eclipse]

I'm noy, a new engineer. I'm making a web application that can communicate asynchronously using Servlet and Ajax. It took some time to resolve the error, so I will keep a record.

Development environment Editor: Eclipse 2019-03 (4.11.0) Web server: Apache Tomcat v9.0 Language: Java Library: ・ Jquery-3.4.1.min.js ・ Jackson-annotations-2.9.9.jar ・ Jackson-core-2.9.9.jar -Jackson-databind-2.9.9.jar

error contents

** HTTP status 500 – Internal Server Error occurs when trying to return a response from Servlet to ajax **

スクリーンショット 2019-07-01 20.08.17.png Chrome developer tools "console" tab

"What is a 500 error ?!" and I wasted a little time, but

スクリーンショット 2019-07-01 20.09.04.png Click on the error and you will find an exception report. "Root cause java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ObjectMapper」

that? The file that defines ObjectMapper should be imported ... With that in mind, when I was reviewing Eclipse in various ways, I found the following warning on the "Problems" tab.

スクリーンショット_2019-07-01_21_22_33.png

Maybe the jackson-XXXXXX-2.9.9.jar file that should have been added to the classpath is not referenced ...?

Cause

** Because the file (jackson-XXXXXX-2.9.9.jar) in which ObjectMapper (Jackson class) is defined cannot be referenced and java.lang.NoClassDefFoundError is displayed. ** **

So, when I googled "eclipse classpath entry is not exported or published", I found the following page and solved it.

https://codeday.me/jp/qa/20190201/208565.html "Spring-mvc-Eclipse warning: XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may occur"

solution

** Delete the jackson-XXXXXX-2.9.9.jar file from the reference library and store it directly in the WEB-INF / lib folder. ** **

スクリーンショット_2019-07-01_21_37_20.png スクリーンショット_2019-07-01_21_43_15.png

Removed the three jackson-XXXXXX-2.9.9.jar files in the reference library with "Exclude from build path".

スクリーンショット_2019-07-01_21_52_25-2.png

Drag and drop the three jackson-XXXXXX-2.9.9.jar files directly into the WebContent / WEB-INF / lib folder.

スクリーンショット 2019-07-01 21.50.10.png

Select "Copy File" and click "OK"

スクリーンショット 2019-07-01 21.55.21.png

The file has been stored.

スクリーンショット_2019-07-01_22_20_36.png

The warnings about the three jackson-XXXXXX-2.9.9.jar files have disappeared. (Ignore the remaining 2 items now)

スクリーンショット 2019-07-01 22.24.53.png

The 500 error disappeared and the Servlet was able to execute.

Recommended Posts

[Servlet / Ajax] How to resolve NoClassDefFoundError [Eclipse]
How to resolve Sprockets :: DoubleLinkError
How to resolve Git conflicts
How to use Eclipse Debug_Shell
How to use scope (JSP & Servlet)
How to resolve Mixed Content errors
[Technical memo] How to resolve errors
How to set Lombok in Eclipse
java Eclipse How to debug javaScript
A memorandum on how to use Eclipse
How to use Apache Derby on Eclipse
How to include Spring Tool in Eclipse 4.6.3?
How to resolve errors when installing Rails 5.1.3
Java: How to send values from Servlet to Servlet
[For beginners] How to debug in Eclipse
[JavaFX] How to write Eclipse permissions in build.gradle
How to color code console output in Eclipse
How to deploy
Resolve NoClassDefFoundError, ClassNotFoundException
How to automatically generate a constructor in Eclipse
How to implement a like feature in Ajax in Rails
How to switch Tomcat context.xml with WTP in Eclipse
How to jump from Eclipse Java to a SQL file
How to download a file (Servlet, HTML, Apache, Tomcat)
How to start tomcat local server without using eclipse
How to Git manage Java EE projects in Eclipse
How to run Java EE Tutial on github on Eclipse
How to debug the generated jar file in Eclipse
How to resolve SSL_connect error in PayPal Ruby SDK
How to develop OpenSPIFe
How to call AmazonSQSAsync
How to use Map
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to adapt Bootstrap
To debug in eclipse
How to use Twitter4J
How to use active_hash! !!
How to install Docker
How to use MapStruct
How to use hidden_field_tag
How to use TreeSet
How to write dockerfile
[How to use label]
How to make shaded-jar
How to write docker-compose
How to use identity
How to use hashes
How to write Mockito
How to create docker-compose
How to use JUnit 5
How to install MySQL
How to write migrationfile
How to build android-midi-lib
How to use Dozer.mapper