我使用的gradle log4j2項目...並同時創造csvlayout我收到以下錯誤:在線程 異常「主要」 java.lang.NoClassDefFoundError:組織/阿帕奇/公/ CSV/CSVFormat異常在線程「主要」 java.lang.NoClassDefFoundError:組織/阿帕奇/公/ 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 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
,我從早上卡住... :(
日Thnx快速回復......我想這在gradle這個,但不知道爲什麼gradle這個沒有下載這個jar ... :(所以我說在外部。 ..你能告訴我y gradle是不是正在下載 –
@BishalGupta下載任何錯誤信息? – Jens
不,我沒有收到任何錯誤信息 –