gpt4 book ai didi

java - Gradle - 线程 "main"java.lang.NoClassDefFoundError : org/slf4j/LoggerFactory 中出现异常

转载 作者:行者123 更新时间:2023-12-02 10:10:13 29 4
gpt4 key购买 nike

Gradle 文件:

buildscript {
ext {
springBootVersion = '1.5.6.RELEASE'
}
repositories {
maven { url 'http://repo1.maven.org/maven2' }
//maven { url 'https://mvnrepository.com/artifact/org.slf4j/slf4j-api' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
//compile("org.slfj4:slf4j-api:1.7.25")
//runtime('org.slfj4:slf4j-simple:1.7.26')

}
}

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

version = '0.0.1-SNAPSHOT'
sourceCompatibility = 1.7

repositories {
maven { url 'http://repo1.maven.org/maven2' }
//maven { url 'https://mvnrepository.com/artifact/org.slf4j/slf4j-api' }
}


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')
testCompile('junit:junit:4.12')
//
// Dimensions dependencies
//
compile group: 'com.serena', name: 'darius', version:'1.0'
compile group: 'com.serena', name: 'dmfile', version:'1.0'
compile group: 'com.serena', name: 'dmnet', version:'1.0'
compile group: 'com.serena', name: 'dmpmcli', version:'1.0'
compile group: 'com.serena', name: 'dmclient', version:'1.0'

// 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'

//compile group: 'org.slf4j', name: '

}




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

我在 Eclipse 上手动将 slj4-api 和 simple 添加到我的类路径中,因此它可以在 Eclipse 上运行,但是当我将其导出到可运行的 JAR 文件并尝试从命令提示符运行它时,它不断弹出此错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

是否有应该在命令提示符下运行的命令,或者这是 eclipse 中的问题

最佳答案

我发现您的依赖项中也有 log4j。这是否意味着您正在尝试使用 slf4j 和 log4j。

以下是有关如何执行此操作的教程:slf4j-with-log4j

只需将其添加到 gradle.build 中即可:

  compile group: 'log4j', name: 'log4j', version: '1.2.17'
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.26'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.26'

这是设置项目目录的方式 Standard Directory Layout

└───maven-project
├───pom.xml
├───README.txt
├───NOTICE.txt
├───LICENSE.txt
└───src
├───main
│ ├───java
│ └────resources
│ └───log4j.properties
└───test
├───java
└───resources

在资源中添加 log4j.properties,这是所有非 java 文件的目录。

log4j.rootCategory=DEBUG, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yy-MM-dd HH:mm:ss:SSS} %5p %t %c{2}:%L - %m%n

但是,该错误可能是由于刷新 gradle 问题造成的。准备好依赖项后,尝试同步 gradle 并干净地重建您的项目。

关于java - Gradle - 线程 "main"java.lang.NoClassDefFoundError : org/slf4j/LoggerFactory 中出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55054762/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com