문제 설명
Eclipse 및 Tomcat ‑ 클래스 로딩 (Eclipse & Tomcat ‑ Class loading)
최근에 Tomcat을 사용하여 Java 클라이언트 프로젝트를 Java 서버 프로젝트로 마이그레이션했는데 프로젝트 라이브러리 종속성이 손상될 수 있습니다.
일반적으로 Eclipse 메뉴 옵션을 통해 라이브러리를 Java 빌드 경로에 포함합니다. 프로젝트 \lib
폴더에 라이브러리를 저장합니다.
Tomcat 서버 빌드를 통해 이 작업을 수행하면 라이브러리 개체에 오류가 발생합니다. 다음을 통해 라이브러리를 별도로 로드해야 할 수도 있음을 이해합니다.
Class.forName(classString);
그러나 이렇게 하면 NoClassDefFoundError
예외가 발생합니다. 그래서 나는 의존성을 잘못로드하고 있다고 생각합니다. 하지만 Eclipse & Tomcat?
또한 "서버에서 실행"을 사용하고 있음을 언급해야 합니다.
참조 솔루션
방법 1:
Apart from the whole eclipse aspect: As you mention tomcat and a server project: You probably have a web application. Web applications, when deployed, include all the jar
‑files that are contained in WEB‑INF/lib
at runtime.
When everything works at compile time, eclipse is happy with the setup. When you get the NoClassDevFoundError at runtime (in tomcat), you most likely need to give tomcat a hint where to find the jar files. And that will be WEB‑INF/lib