簡體   English   中英

盡管引用了 eclipse 中的庫並在 build.gradle 中指定了依賴關系,為什么我得到“java.lang.NoClassDefFoundError”?

[英]Why am I getting "java.lang.NoClassDefFoundError" despite referencing the library in eclipse and specifying the dependency in build.gradle?

org/apache/commons/compress/archivers/tar/TarArchiveInputStream 的錯誤被拋出,如此處所示

我在 eclipse 中引用了這個庫(如此處所示

build.gradle 中也指定了依賴關系。 gradle文件的內容:

plugins {
    id 'org.spongepowered.plugin' version '0.9.0'
}

group = pluginGroup
version = pluginVersion

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

dependencies {
    compileOnly 'org.spongepowered:spongeapi:7.2.0'
    annotationProcessor 'org.spongepowered:spongeapi:7.2.0'
    compile 'org.apache.commons:commons-compress:1.21'
}

sponge.plugin.id = pluginId

Eclipse 也不會標記任何錯誤。 tarInput.getNextTarEntry()等代碼行以正確的顏色顯示,沒有紅色下划線,eclipse 甚至自動完成在 commons-compress 中找到的方法名稱。

鑒於 eclipse似乎與依賴關系正常工作,並且鑒於運行./gradlew build導致成功構建,因此我不知道為什么會收到java.lang.NoClassDefFoundError錯誤。

@nitind 有幫助。 我專注於運行時,發現問題與我的 build.gradle 文件有關(即使構建成功。):我將其更改為這個並且錯誤消失了:

buildscript {
        repositories {
                mavenCentral()
                }
}

plugins {
    id 'org.spongepowered.plugin' version '0.9.0'
}

apply plugin: 'java'

group = pluginGroup
version = pluginVersion

sourceCompatibility = '1.8'
targetCompatibility = '1.8'

dependencies {
    compileOnly 'org.spongepowered:spongeapi:7.2.0'
    annotationProcessor 'org.spongepowered:spongeapi:7.2.0'
    compile 'org.apache.commons:commons-compress:1.21'
}

jar {
        from configurations.compile.collect { zipTree it }
}

sponge.plugin.id = pluginId

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM