gpt4 book ai didi

java - 线程 "main"java.lang.NoClassDefFoundError : org/apache/commons/csv/CSVFormat 中出现异常

转载 作者:行者123 更新时间:2023-11-30 02:51:06 26 4
gpt4 key购买 nike

我正在使用 log4j2 的 gradle 项目...并且在创建 csvlayout 时遇到以下错误:线程“main”java.lang.NoClassDefFoundError中出现异常:org/apache/commons/csv/CSVFormat

CsvParameterLayoutExample 类

package log4j_tutorial;
import org.apache.logging.log4j.LogManager;

import org.apache.logging.log4j.Logger;

public class CsvParameterLayoutExample {

private static final Logger logger = LogManager.getLogger();

public static void main(String[] args) {
int val1 = 10, val2 = 11, val3 = 12;
logger.trace("Trace Message!", val1, val2, val3);
logger.debug("Debug Message!", val1, val2, val3);
logger.info("Info Message!", val1, val2, val3);
logger.warn("Warn Message!", val1, val2, val3);
logger.error("Error Message!", val1, val2, val3);
logger.fatal("Fatal Message!", val1, val2, val3);
}

}

log4j2.xml

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" xmlns="http://logging.apache.org/log4j/2.0/config" packages="log4j_tutorial">
<Appenders>
<File name="my_file_appender" fileName="C:/Users/bishal.gupta/Desktop/Testing/CsvLog4jTest/application.log">
<CsvParameterLayout delimiter=","/>
</File>
</Appenders>

<Loggers>
<Root level="info">
<AppenderRef ref="my_file_appender" />
</Root>
</Loggers>
</Configuration>

build.gradle对于依赖项

异常(exception):

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2442)
at java.lang.Class.getDeclaredMethods(Class.java:1808)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.createBuilder(PluginBuilder.java:149)
at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:119)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:888)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:828)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:820)
at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:820)
at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:449)
at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:197)
at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:209)
at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:492)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:562)
at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:578)
at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:214)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:145)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:182)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:455)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:441)
at log4j_tutorial.CsvParameterLayoutExample.<clinit>(CsvParameterLayoutExample.java:7)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.csv.CSVFormat
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 22 more

我从早上就陷入困境......:(

最佳答案

您必须添加 commons-csv 作为依赖项。

如果您使用 gradle 作为问题标记,请添加以下行:

// https://mvnrepository.com/artifact/org.apache.commons/commons-csv
compile group: 'org.apache.commons', name: 'commons-csv', version: '1.4'

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

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