JSON 개체를 구문 분석하는 동안 NoClassDefFoundError JsonAutoDetect가 발생했습니다.
Amazon의 클라우드 서비스를 이용하여 웹 앱을 개발 중인데 JSON 오브젝트를 활용해야 합니다.프로젝트 셋업 방법은 사용자가 정보를 입력하고 제출하는 HTML 양식을 가지고 있습니다.데이터가 제출되면 온라인 데이터베이스에 저장되고 확인 이메일이 전송됩니다.데이터를 데이터베이스로 전송하기 전에 모든 데이터를 JSON 개체에 저장해야 합니다.Java에서 실행되는 내 servlet은 다음과 같습니다.
public class FormHandling extends HttpServlet {
//doGet function
public void doGet (HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// In this part of the code I take in the user data and build an HTML
// page and return it to the user
// Create String Mapping for User Data object
Map<String,Object> userData = new HashMap<String,Object>();
// Map the names into one struct. In the code below we are creating
// values for the nameStruct from the information the user has
// submitted on the form.
Map<String,String> nameStruct = new HashMap<String,String>();
nameStruct.put("fName", request.getParameter("fname"));
nameStruct.put("lName", request.getParameter("lname"));
nameStruct.put("mInit", request.getParameter("minit"));
// Map the three email's together (providing there are 3).
// This is the same logic as the names.
Map<String,String> emailStruct = new HashMap<String,String>();
emailStruct.put("email", request.getParameter("email1"));
emailStruct.put("email", request.getParameter("email2"));
emailStruct.put("email", request.getParameter("email3"));
// Put Name Hash Value Pair inside User Data Object
userData.put("name", nameStruct);
userData.put("emails", emailStruct);
userData.put("age", 22);
// Create the Json data from the userData
createJson(userData);
// Close writer
out.close();
}
public File createJson(Map<String,Object> userData)
throws JsonGenerationException, JsonMappingException, IOException {
File user = new File("user.json");
// Create mapper object
ObjectMapper mapper = new ObjectMapper();
// Add the userData information to the json file
mapper.writeValue(user, userData);
return user;
}
}
이 코드를 사용하여 폼을 전송하면 다음 오류 메시지가 나타납니다.
java.displaces를 클릭합니다.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonAutoDetect com.fasterxml.jackson.databind.내성적인가시성Checker$Std.(가시성Checker.java:169) com.fasterxml.jackson.databind.오브젝트 맵퍼(ObjectMapper.java:197) edu.tcnj.FormHandling.createJson(FormHandling.java:115)edu.tcnj.FormHandling.doGet(FormHandling.java:104)edu.tcnj.FormHandling.doPost(FormHandling.java:131) javax.servlet.http.HttpServlet.service(HttpServlet.java:641) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
그 에러가 잭슨 데이터바인드 라이브러리를 찾지 못하고 있다는 것을 알게 되었습니다.저는 Eclipse에서 개발 중입니다.빌드 패스가 가끔 복잡해지는 것을 알고 있기 때문에 Web Content에도 라이브러리를 배치했습니다.WEB-INF\lib 폴더.이것으로 지금까지의 고민은 해결되었습니다.하지만 이번에는 제 문제가 해결되지 않는 것 같습니다.필요한 라이브러리와 클래스가 있는지 물리적으로 확인하기 위해 항아리 파일도 열었습니다.나는 도서관을 포함하기 위해 모든 곳을 찾아보고 여러 가지 방법을 찾아봤지만, 아무 것도 효과가 없는 것 같다.
앞으로 이곳에 오시는 분들에게 답은 다음과 같습니다.
복사만 한 경우jackson core
그리고.jackson databind
, 필요한 경우jackson annotations
사용하다ObjectMapper
.
예를 들어 다음과 같은 것이 있는지 확인합니다.
[16:32:01]:/android-project/libs master]$ ls -lAF
total 2112
-rw-r--r--@ 1 jeffamaphone staff 33525 Jun 18 16:06 jackson-annotations-2.0.2.jar
-rw-r--r--@ 1 jeffamaphone staff 193693 Jun 7 16:42 jackson-core-2.0.2.jar
-rw-r--r--@ 1 jeffamaphone staff 847121 Jun 18 15:22 jackson-databind-2.0.2.jar
maven 사용자를 위해 @jeffamaphone의 우수한 답변을 확대합니다.
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.7.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.7.3</version>
</dependency>
또는 다음 그래들 구성:
compile 'com.fasterxml.jackson.core:jackson-core:2.2.2'
compile 'com.fasterxml.jackson.core:jackson-databind:2.2.2'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.2'
만약 당신이 maven을 사용하고 나의 경우처럼 모든 도서관이 제 위치에 있다면,mvn clean
그리고.mvn install
문제를 해결했습니다.
exclipse 현상 중에 Tomcat을 사용하다가 이 오류가 발생한 경우(republish/clean을 눌렀기 때문일 수 있음)
프로젝트 우클릭 -> 맵 -> 프로젝트 갱신...
이 문제를 해결해 주셨어요.
또한 요한 셰버그의 의존관계도 포함시켰습니다.
언급URL : https://stackoverflow.com/questions/10094300/noclassdeffounderror-jsonautodetect-while-parsing-json-object
'programing' 카테고리의 다른 글
ON [PRIMAY]는 무슨 뜻입니까? (0) | 2023.04.07 |
---|---|
SQL Server에서 데이터베이스 목록 가져오기 (0) | 2023.04.07 |
Wordpress - 편집기에 html/텍스트 삽입 (0) | 2023.03.18 |
ngpattern을 사용하여 자연 입력 번호 확인 (0) | 2023.03.08 |
Angular 2 Form Group에서 모든 검증 오류를 가져옵니다. (0) | 2023.03.08 |