nhkiiim / TIL

Today I Learned
https://github.com/nhkiiim/TIL/discussions
1 stars 0 forks source link

Java: NoClassDefFoundError #222

Open nhkiiim opened 1 month ago

nhkiiim commented 1 month ago

개발환경 세팅 중 Gradle refresh 과정에서 NoClassDefFoundError 발생

NoClassDefFoundError

https://docs.oracle.com/javase/8/docs/api/java/lang/NoClassDefFoundError.html

"클래스가 컴파일 될 당시 존재했지만 더 이상 정의를 찾을 수 없습니다."

nhkiiim commented 1 month ago

📢 build.gradle 설정 오류로 발생한 것으로 확인 -> 의존성 범위 수정으로 해결 완료

nhkiiim commented 1 month ago

build.gradle 설정 오류로 NoClassDefFoundError 발생하는 경우

1. 의존성 누락

dependencies {
    compileOnly 'com.example:some-library:1.0.0' // 런타임 시 필요하다면 compileOnly 대신 implementation을 사용
    implementation 'com.example:another-library:1.0.0'
}

3. 멀티 모듈 프로젝트 설정 오류

dependencies {
    implementation project(':another-module') // 다른 모듈에 대한 의존성 추가
}

4. 레포지토리 설정 오류

repositories {
    mavenCentral() // 또는 jcenter(), google() 등 필요한 리포지토리를 추가
}

5. 플러그인 설정 오류

plugins {
    id 'java' // 필요한 플러그인 적용
}
nhkiiim commented 1 month ago

ClassNotFoundException 과의 차이

ClassNotFoundException

NoClassDefFoundError

nhkiiim commented 1 month ago

🎃 기타 다양한 발생 원인 참고 https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java