简体   繁体   English

Gradle-线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory

[英]Gradle - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory

Gradle file: 摇篮文件:

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

I added the slj4-api and simple into my classpath, manually on eclipse, so it works on eclipse, however when I export it into a runnable JAR File and try to run it from the command prompt it keeps popping up this error: 我在eclipse上手动将slj4-api和simple添加到我的类路径中,因此它可以在eclipse上使用,但是当我将其导出到可运行的JAR文件并尝试从命令提示符运行它时,它会不断弹出此错误:

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

Is there a commands that supposed to be ran on the command prompt or is this issue within eclipse 是否有应该在命令提示符下运行的命令,还是Eclipse中的此问题?

I see that you also have log4j in your dependency. 我看到您的依赖项中也有log4j。 Does that mean you are trying to use slf4j and log4j. 这是否意味着您正在尝试使用slf4j和log4j。

Here is a tutorial on how to do that: slf4j-with-log4j 这是有关如何执行此操作的教程: slf4j-with-log4j

Simply you need to add this in your gradle.build: 只需将其添加到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'

this is how you set up your project directory Standard Directory Layout 这是设置项目目录标准目录布局的方式

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

add log4j.properties in your resources, thats the directory for all your non java files. 在您的资源中添加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

The error however can be due a refresh gradle issue. 但是,该错误可能是由于刷新gradle问题引起的。 after you have your dependencies in place, Try to sync gradle and clean rebuild your project. 放置好依赖项后,尝试同步gradle并清理重建项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 线程“ main”中的Gradle异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Gradle Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory Java:线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Java: Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory Spring工具套件中的线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in Spring tool suite XUGGLE ERROR:线程“main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - XUGGLE ERROR: Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory RabbitMQ - 线程“main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - RabbitMQ - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory Java + Maven +在线程“main”中生成可执行jar +异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Java + Maven + make executable jar + Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory java.lang.NoClassDefFoundError: OSGi 中的 org/slf4j/LoggerFactory - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in OSGi 休眠-java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Hibernate - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 问题 - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory problem 线程“main”中的Yahoo BOSS异常java.lang.NoClassDefFoundError:org / slf4j / ILoggerFactory - Yahoo BOSS Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/ILoggerFactory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM