gpt4 book ai didi

java - NoClassDefFoundError:使用Gradle创建可运行的* .jar时出现org/slf4j/LoggerFactory

转载 作者:行者123 更新时间:2023-12-03 06:04:09 26 4
gpt4 key购买 nike

我只是想借助gradle和应用程序插件为我的应用程序创建可运行的* .jar文件。

构建过程没有错误, list 文件可以正常运行,等等,但是在运行* .jar文件时会发生以下情况:

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at main.Launcher.<clinit>(Launcher.java:19)
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)
... 1 more
Exception in thread "main"
Process finished with exit code 1

似乎很明显我缺少该库,但是它已指定:

build.gradle
group 'Comparator'
version '0.9'

apply plugin: 'java'
apply plugin: 'application'

mainClassName = "main.Launcher"

compileJava {
//enable compilation in a separate daemon process
options.fork = true
//enable incremental compilation
options.incremental = true
}

repositories {
mavenCentral()

}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.11'
// GraphStream Core
compile group: 'org.graphstream', name: 'gs-core', version: '1.3'
// GraphStream
//UI
compile group: 'org.graphstream', name: 'gs-ui', version: '1.3'
// GraphStream
//algo
compile group: 'org.graphstream', name: 'gs-algo', version: '1.3'
// Jena
// https://mvnrepository.com/artifact/org.apache.jena/jena-arq
compile group: 'org.apache.jena', name: 'jena-arq', version: '2.13.0'
compile group: 'org.apache.jena', name: 'jena-querybuilder', version: '2.13.0'

// Log
compile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.21'

compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.0.9'
compile group: 'ch.qos.logback', name: 'logback-core', version: '1.0.9'
// https://mvnrepository.com/artifact/org.jgrapht/jgrapht-core
compile group: 'org.jgrapht', name: 'jgrapht-core', version: '0.9.2'
compile group: 'org.jgrapht', name: 'jgrapht-jdk1.5', version: '0.7.3'
compile group: 'org.jgrapht', name: 'jgrapht-ext', version: '0.9.2'
// CSV parser
compile group: 'com.univocity', name: 'univocity-parsers', version: '1.0.0'

// https://mvnrepository.com/artifact/com.google.guava/guava
compile group: 'com.google.guava', name: 'guava', version: '11.0.2'


}

jar {
manifest {
attributes 'Main-Class': mainClassName,
'Class-Path': configurations.runtime.files.collect { "$it.name" }.join(' ')
}
}

创建的 list 如下:
Manifest-Version: 1.0
Main-Class: main.Launcher
Class-Path: gs-core-1.3.jar gs-ui-1.3.jar gs-algo-1.3.jar jena-arq-2.1
3.0.jar jena-querybuilder-2.13.0.jar slf4j-api-1.7.21.jar logback-cla
ssic-1.0.9.jar logback-core-1.0.9.jar jgrapht-core-0.9.2.jar jgrapht-
jdk1.5-0.7.3.jar jgrapht-ext-0.9.2.jar univocity-parsers-1.0.0.jar gu
ava-11.0.2.jar junit-4.12.jar pherd-1.0.jar mbox2-1.0.jar scala-libra
ry-2.10.1.jar commons-math-2.1.jar commons-math3-3.4.1.jar jfreechart
-1.0.14.jar jena-core-2.13.0.jar httpclient-4.2.6.jar jsonld-java-0.5
.1.jar httpclient-cache-4.2.6.jar libthrift-0.9.2.jar commons-csv-1.0
.jar commons-lang3-3.3.2.jar slf4j-log4j12-1.7.6.jar log4j-1.2.17.jar
apache-jena-libs-2.13.0.pom jgraphx-2.0.0.1.jar jgraph-5.13.0.0.jar
jsr305-1.3.9.jar hamcrest-core-1.3.jar jcommon-1.0.17.jar itext-2.1.5
.jar jena-iri-1.1.2.jar xercesImpl-2.11.0.jar httpcore-4.2.5.jar comm
ons-codec-1.6.jar jackson-core-2.3.3.jar jackson-databind-2.3.3.jar j
ena-tdb-1.1.2.jar bcmail-jdk14-138.jar bcprov-jdk14-138.jar jackson-a
nnotations-2.3.0.jar jcl-over-slf4j-1.7.7.jar commons-logging-1.1.1.j
ar xml-apis-1.4.01.jar

请注意,它确实包括slf4j,但我仍然遇到异常。
有任何想法吗?

谢谢!

最佳答案

一段时间后,我来到了(我认为是)解决方案。对生成的类路径有不同的依赖关系是一个大问题。从头开始生成项目并导入代码和资源被证明是成功的。

如果您遇到相同的错误,我提出相同的解决方案,则只需从头开始重建项目即可。

是的,可能有更好的解决方案,但我在1个月内找不到。

关于java - NoClassDefFoundError:使用Gradle创建可运行的* .jar时出现org/slf4j/LoggerFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39747780/

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