我已经尝试在我的项目中让这个工作三天,并创建了一个简单的项目来测试。我在这里搜索了非常相似的问题,但没有找到任何有助于解决我遇到的错误的方法。我什至重新格式化了我的 Fedora 25,因为它可以在 Windows 10 上运行,但仍然没有。我还启用了 Intellij-2016.3.4 注释处理中的设置和其他设置,根据其他答案应该已经修复它,但它不会改变任何东西。请任何帮助将不胜感激!!!
线程“main”中的异常 java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory at com.sammy.CheckLog.(CheckLog.java:8) 原因:java.lang.ClassNotFoundException: org.slf4j.LoggerFactory at java.net。com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)sun.misc中的 java.lang.ClassLoader.loadClass(ClassLoader.java:424) 中的 URLClassLoader.findClass(URLClassLoader.java:381) 。 Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 还有 1 个
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class CheckLog {
public static void main(String... args){
log.info("I'm Here!! ");
}
}
下面是我的 build.gradle 文件,其中定义了 lombok 以及相关的 slf4j 依赖项。
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a commented-out sample Java project to get you started.
* For more details take a look at the Java Quickstart chapter in the Gradle
* user guide available at https://docs.gradle.org/3.4/userguide/tutorial_java_projects.html
*/
// Apply the java plugin to add support for Java
apply plugin: 'java'
apply plugin: 'application'
mainClassName = 'com.sammy.CheckLog'
// In this section you declare where to find the dependencies of your project
repositories {
// Use 'jcenter' for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
// In this section you declare the dependencies for your production and test code
dependencies {
// The production code uses the SLF4J logging API at compile time
compileOnly 'org.slf4j:slf4j-api:1.7.24'
compileOnly 'org.slf4j:slf4j-simple:1.7.24'
compileOnly 'org.projectlombok:lombok:1.16.14'
// Declare the dependency for your favourite test framework you want to use in your tests.
// TestNG is also supported by the Gradle Test task. Just change the
// testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add
// 'test.useTestNG()' to your build script.
testCompile 'junit:junit:4.12'
}
更新:更改为“编译”后,它在命令行上运行,而不是来自 Intellij,因为它似乎使用它自己的运行时来解释它,而 gradle 使用我定义的那个。jdk1.8.0_121