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
** HTTP status 500 – Internal Server Error occurs when trying to return a response from Servlet to ajax **
Chrome developer tools "console" tab"What is a 500 error ?!" and I wasted a little time, but
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.
Maybe the jackson-XXXXXX-2.9.9.jar file that should have been added to the classpath is not referenced ...?
** 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"
** Delete the jackson-XXXXXX-2.9.9.jar file from the reference library and store it directly in the WEB-INF / lib folder. ** **
Removed the three jackson-XXXXXX-2.9.9.jar files in the reference library with "Exclude from build path".
Drag and drop the three jackson-XXXXXX-2.9.9.jar files directly into the WebContent / WEB-INF / lib folder.
Select "Copy File" and click "OK"
The file has been stored.
The warnings about the three jackson-XXXXXX-2.9.9.jar files have disappeared. (Ignore the remaining 2 items now)
The 500 error disappeared and the Servlet was able to execute.
Recommended Posts