java - 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
解决方案
推荐阅读
- javascript - Firebase 和 Angular:*ngFor 无需重新加载图像
- ruby-on-rails - redmine收不到邮件
- javascript - JavaScript 一次替换文本中的多个字符
- linux - curl 是否认为方案协议是允许的?
- api - 为什么亚马逊的供应商中心 API 没有在特定日期更改 PO?
- python - 如何将列中的值更改为假值
- c# - 调试 IIS Express 身份验证问题
- node.js - 如何有条件地选择 NoSQL 数据库?
- ruby-on-rails - 未加载库:rubygems/core_ext/kernel_require
- angular - 识别Angular中的单击按钮