首页 > 解决方案 > Gradle - 引起:java.lang.NoSuchMethodError:org.apache.log4j.Logger.getLoggerRepository()Lorg/apache/log4j/spi/LoggerRepository

问题描述

我在 Eclipse IDE 中有一个使用 gradle 插件的项目,它在 IDE 中成功运行和运行,但是,当我使用 eclipse 将项目导出到 jar 文件并通过 cmd、java -jar test1.jar 运行它时,我得到这个重复出现的错误:

“引起:java.lang.NoSuchMethodError:org.apache.log4j.Logger.getLoggerRepository()Lorg/apache/log4j/spi/LoggerRepository;”

据我了解,gradle 正在检索 log4j-1.2.17.jar 文件,并在使用 eclipse 导出到可运行的 jar 时打包,但我仍然收到此错误。

构建.gradle:

buildscript {
    ext {
        springBootVersion = '1.5.6.RELEASE'
    }
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.7

repositories {
    mavenCentral()
        flatDir {
         dirs 'F:/flatRepo'
     }     
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-security')
    compile('org.springframework.session:spring-session')
    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    runtime('org.springframework.boot:spring-boot-devtools')
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    runtime('org.hsqldb:hsqldb')
    runtime('mysql:mysql-connector-java')
    testCompile('org.springframework.boot:spring-boot-starter-test')
    testCompile('org.springframework.security:spring-security-test')
    //
//   Dimensions dependencies

    // log4j
    compile group: 'log4j', name: 'log4j', version: '1.2.17'

// https://mvnrepository.com/artifact/javax.mail/mail
compile group: 'javax.mail', name: 'mail', version: '1.4.1'

// https://mvnrepository.com/artifact/commons-codec/commons-codec
compile group: 'commons-codec', name: 'commons-codec', version: '1.4'

// https://mvnrepository.com/artifact/javax.inject/javax.inject
compile group: 'javax.inject', name: 'javax.inject', version: '1'


}

task setHttpProxyFromEnv {
    def map = ['HTTP_PROXY': 'http', 'HTTPS_PROXY': 'https']
    for (e in System.getenv()) {
        def key = e.key.toUpperCase()
        if (key in map) {
            def base = map[key]
            def url = e.value.toURL()
            println " - systemProp.${base}.proxy=${url.host}:${url.port}"
            System.setProperty("${base}.proxyHost", url.host.toString())
            System.setProperty("${base}.proxyPort", url.port.toString())
        }
    }
}

build.dependsOn setHttpProxyFromEnv

标签: javaeclipsegradlejarlog4j

解决方案


推荐阅读