添加依赖项会导致找不到主类。

huangapple go评论62阅读模式
英文:

Adding dependency causes main class to not be found

问题

添加com.spotify:docker-client:3.5.12依赖到build.gradle时,导致我的主类“com.gamedash.daemon.Main”无法找到。我完全不知道这可能是什么原因。删除这个依赖可以解决这个问题。

build.gradle

group 'com.gamedash.daemon'
version '0.1'
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'idea'

sourceCompatibility = 9
targetCompatibility = 9

repositories {

    mavenCentral()
    maven {

        url 'https://jetbrains.bintray.com/pty4j'

    }

}

application {

    mainClassName = 'com.gamedash.daemon.Main'

}

jar {

    manifest {

        attributes(

            'Main-Class': 'com.gamedash.daemon.Main'

        )
    }
    from {

        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }

    }

}

sourceSets {

    main {

        resources {

            srcDirs "src/main/resources", "src/main/configs"

        }

    }

}

buildscript {

    repositories {

        mavenCentral()

    }
    dependencies {

        classpath 'net.sf.proguard:proguard-gradle:6.2.2'

    }

}

dependencies {

    implementation('me.tongfei:progressbar:0.7.4')
    implementation('com.google.guava:guava:28.2-jre')
    implementation('com.corundumstudio.socketio:netty-socketio:1.7.17')
    implementation('org.jetbrains.pty4j:pty4j:0.8.6')
    implementation('commons-io:commons-io:2.6')
    implementation('org.zeroturnaround:zt-zip:1.13')
    implementation('org.apache.httpcomponents:httpclient:4.5.8')
    implementation('com.beust:jcommander:1.78')
    implementation('com.google.code.gson:gson:2.8.5')
    implementation('com.github.oshi:oshi-core:4.4.2')
    implementation('net.java.dev.jna:jna:5.3.1')
    implementation('net.java.dev.jna:jna-platform:5.3.1')
    implementation('org.apache.commons:commons-lang3:3.9')
    implementation('com.sparkjava:spark-core:2.9.1')
    implementation('org.slf4j:slf4j-api:1.7.6')
    implementation('org.slf4j:slf4j-log4j12:1.7.5')
    implementation('org.apache.mina:mina-core:2.0.0-M2')
    implementation('org.apache.ftpserver:ftplet-api:1.1.1')
    implementation('org.apache.ftpserver:ftpserver-core:1.1.1')
    implementation('org.apache.sshd:sshd-core:2.4.0')
    implementation('org.apache.sshd:sshd-sftp:2.4.0')
    compile('com.spotify:docker-client:3.5.12:shaded')
    implementation('org.beryx:text-io:3.3.0')
    implementation('com.fasterxml.jackson.core:jackson-core:2.9.8')
    implementation('com.fasterxml.jackson.core:jackson-annotations:2.9.8')
    implementation('com.fasterxml.jackson.core:jackson-databind:2.9.8')
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.4'
    implementation group: 'commons-validator', name: 'commons-validator', version: '1.4.0'
    implementation files('lib/icmp4j-all.jar')
    implementation files('lib/Schokker-IT-Rest-Client.jar')
    implementation files('lib/com.gamedash.daemon.common.jar')

}

task obfuscate(type: proguard.gradle.ProGuardTask) {

    configuration 'proguard.txt'
    injars "build/libs/gamedash-daemon-${version}.jar"
    outjars "build/libs/gamedash-daemon-${version}-obfuscated.jar"

}
英文:

When adding the com.spotify:docker-client:3.5.12 dependency to build.gradle, it causes my main class "com.gamedash.daemon.Main" to not be found. I have absolutely no clue what this might be causing. Removing the dependency resolves the issue.

build.gradle

group 'com.gamedash.daemon'
version '0.1'
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'eclipse'
apply plugin: 'idea'
sourceCompatibility = 9
targetCompatibility = 9
repositories {
mavenCentral()
maven {
url 'https://jetbrains.bintray.com/pty4j'
}
}
application {
mainClassName = 'com.gamedash.daemon.Main'
}
jar {
manifest {
attributes(
'Main-Class': 'com.gamedash.daemon.Main'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
sourceSets {
main {
resources {
srcDirs "src/main/resources", "src/main/configs"
}
}
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'net.sf.proguard:proguard-gradle:6.2.2'
}
}
dependencies {
implementation('me.tongfei:progressbar:0.7.4')
implementation('com.google.guava:guava:28.2-jre')
implementation('com.corundumstudio.socketio:netty-socketio:1.7.17')
implementation('org.jetbrains.pty4j:pty4j:0.8.6')
implementation('commons-io:commons-io:2.6')
implementation('org.zeroturnaround:zt-zip:1.13')
implementation('org.apache.httpcomponents:httpclient:4.5.8')
implementation('com.beust:jcommander:1.78')
implementation('com.google.code.gson:gson:2.8.5')
implementation('com.github.oshi:oshi-core:4.4.2')
implementation('net.java.dev.jna:jna:5.3.1')
implementation('net.java.dev.jna:jna-platform:5.3.1')
implementation('org.apache.commons:commons-lang3:3.9')
implementation('com.sparkjava:spark-core:2.9.1')
implementation('org.slf4j:slf4j-api:1.7.6')
implementation('org.slf4j:slf4j-log4j12:1.7.5')
implementation('org.apache.mina:mina-core:2.0.0-M2')
implementation('org.apache.ftpserver:ftplet-api:1.1.1')
implementation('org.apache.ftpserver:ftpserver-core:1.1.1')
implementation('org.apache.sshd:sshd-core:2.4.0')
implementation('org.apache.sshd:sshd-sftp:2.4.0')
compile('com.spotify:docker-client:3.5.12:shaded')
implementation('org.beryx:text-io:3.3.0')
implementation('com.fasterxml.jackson.core:jackson-core:2.9.8')
implementation('com.fasterxml.jackson.core:jackson-annotations:2.9.8')
implementation('com.fasterxml.jackson.core:jackson-databind:2.9.8')
compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.2.4'
implementation group: 'commons-validator', name: 'commons-validator', version: '1.4.0'
implementation files('lib/icmp4j-all.jar')
implementation files('lib/Schokker-IT-Rest-Client.jar')
implementation files('lib/com.gamedash.daemon.common.jar')
}
task obfuscate(type: proguard.gradle.ProGuardTask) {
configuration 'proguard.txt'
injars "build/libs/gamedash-daemon-${ version }.jar"
outjars "build/libs/gamedash-daemon-${ version }-obfuscated.jar"
}

答案1

得分: 1

结果发现所涉及的库使用了Bouncycastle,因此需要一个已签名的jar文件才能运行。如果错误消息直接告诉我需要一个已签名的jar文件而不是告诉我找不到该类,那会更加愉快。

通过在我的build.gradle中添加以下规则进行修复:

exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
英文:

Turns out that the library in question uses Bouncycastle and thus requires a signed jar to run. Would have been much more pleasant if the error message would have said so, instead of telling me that the class was not found.

Fixed it by adding the following rule to my build.gradle

exclude 'META-INF/*.RSA', 'META-INF/*.SF','META-INF/*.DSA'

huangapple
  • 本文由 发表于 2020年9月17日 16:44:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/63934406.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定