gpt4 book ai didi

maven - 使用Gradle找不到slf4j LoggerFactory类定义

转载 作者:行者123 更新时间:2023-12-03 05:11:58 24 4
gpt4 key购买 nike

我正在尝试构建和运行在IntelliJ中使用slf4j登录的Spark网络服务器。它可以在最初用于添加日志记录的计算机上构建良好(在IntelliJ中也可以),但不能在我的计算机上构建。

这是完整的build.gradle文件(有关使用记录器的部分,请参见project(':webserver'):

buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "gradle.plugin.com.avast.gradle:docker-compose-gradle-plugin:0.3.27"
}
}

subprojects {
repositories {
mavenLocal()
mavenCentral()
jcenter()
}

apply plugin: "java"
apply plugin: "idea"
apply plugin: "checkstyle"
apply plugin: "pmd"
apply plugin: "findbugs"
apply plugin: "application"
apply plugin: "com.avast.gradle.docker-compose"

checkstyle {
configFile = "../config/checkstyle/checkstyle.xml" as File
toolVersion = "6.0"
}
}

project(':webserver') {
mainClassName = "org.passport.webserver.WebServer"
dependencies {
compile project(':core')
compile "com.sparkjava:spark-core:2.6.0"
testCompile 'junit:junit:4.12'
compile group: 'org.json', name: 'json', version: '20090211'
compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
}

sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}

project(':customsUI') {
mainClassName = "org.passport.customsui.CustomsUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}

sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}

project(':handlerUI') {
mainClassName = "org.passport.handlerui.HandlerUI"
dependencies {
compile project(':core')
testCompile 'junit:junit:4.12'
}

sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}

project(':core') {
mainClassName = "org.passport.core.PassPortChaincode"
dependencies {
compile 'io.grpc:grpc-all:0.13.2'
compile 'commons-cli:commons-cli:1.3.1'
compile 'org.glassfish:javax.json:1.1.0-M1'
compile files('lib/shim-client-1.0.jar')
testCompile 'junit:junit:4.12'
}

sourceSets {
main {
java {
srcDir 'src/main/java/'
}
}
}
}

这是使用记录器的代码:
package org.passport.webserver;

import org.passport.webserver.endpoints.ContainerClaimDao;
import org.passport.webserver.endpoints.PackageClaimDao;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static spark.Spark.before;
import static spark.Spark.get;
import static spark.Spark.path;
import static spark.Spark.post;

/**
* The server matches requests (routs) and calls the appropriate endpoints.
*/
public final class Server {

private static Logger logger = LoggerFactory.getLogger(Server.class);
private static ContainerClaimDao containers = new ContainerClaimDao();
private static PackageClaimDao packages = new PackageClaimDao();

private Server() {

}

/**
* Starts the router.
* @param args run arguments
*/
public static void main(String[] args) {
path("/containers/:container-id", () -> {
before("/*", (q, a) -> logger.info("Received api call: " + q.url() + "."));

post("", (request, response) -> containers.add(request, response));

get("/container-claims", (request, response) -> containers.get(request, response));

get("/package-claims", (request, response) -> packages.get(request, response));

});
}

}

这是我得到的错误:
"C:\Program Files\Java\jdk1.8.0_91\bin\java" -Didea.launcher.port=7534 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.8.0_91\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_91\jre\lib\rt.jar;C:\Users\lover\repositories\passport\webserver\build\classes\main;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 2016.2.4\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.passport.webserver.Server
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at org.passport.webserver.Server.<clinit>(Server.java:18)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 4 more

我看过关于StackOverflow的几个问题,但似乎没有一个能解决问题:
  • java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory-我正在用gradle构建,不要认为我应该下载/在我的类路径中放入一些jar
  • ClassNotFoundException: org.slf4j.LoggerFactory-与上述
  • 相同
  • NoClassDefFoundError: org/slf4j/Logger-再次 jar
  • Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory-我不确定“fat jars” / ShadowJar是否适用,也不确定如何修改构建文件以使用它们
  • NoClassDefFoundError: org/slf4j/LoggerFactory while creating a runnable *.jar with gradle-我已经尝试过几次刷新gradle,重新启动IntelliJ,甚至重新启动计算机
  • Gradle Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory-参见下文

  • 我尝试了以下依赖项:
  • compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.6.1'
  • compile 'org.slf4j:slf4j-api:1.7.24'compile 'org.slf4j:slf4j-simple:1.7.24'
  • compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'

  • 这些似乎都没有改变。有任何想法吗?

    最佳答案

    如果您使用Gradle,请将这两行添加到build.gradle依赖项中以使用Spark 2.6.0
    compile "com.sparkjava:spark-core:2.6.0"compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.21'

    关于maven - 使用Gradle找不到slf4j LoggerFactory类定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111973/

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