我从http://logging.apache.org/log4j/下载了“apache-log4j-2.0-beta9-bin”并将其删除并添加到我的项目中。然后我在我的项目中编写了一个配置属性文件,如下所示
# Define the root logger with appender file
log = X:\logs
log4j.rootLogger = DEBUG, FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern=%m%n
我编写了示例程序来测试它,示例程序如下所示。
public class Log4jExample {
static Logger log = Logger.getLogger(Log4jExample.class.getName());
public static void main(String[] args)throws IOException{
log.debug("Hello this is an debug message");
log.info("Hello this is an info message");
}
}
执行时遇到此错误,请提供建议。
java.lang.NoClassDefFoundError: org/apache/flume/Event
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:186)
at org.apache.logging.log4j.core.config.plugins.PluginManager.decode(PluginManager.java:241)
at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:152)
at org.apache.logging.log4j.core.config.plugins.PluginManager.collectPlugins(PluginManager.java:130)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:116)
at org.apache.logging.log4j.core.pattern.PatternParser.<init>(PatternParser.java:102)
at org.apache.logging.log4j.core.layout.PatternLayout.createPatternParser(PatternLayout.java:183)
at org.apache.logging.log4j.core.layout.PatternLayout.<init>(PatternLayout.java:115)
at org.apache.logging.log4j.core.layout.PatternLayout.createLayout(PatternLayout.java:219)
at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:51)
at org.apache.logging.log4j.core.LoggerContext.<init>(LoggerContext.java:63)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:217)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:114)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:81)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:83)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:34)
at org.apache.logging.log4j.LogManager.getContext(LogManager.java:200)
at org.apache.log4j.Logger$PrivateManager.getContext(Logger.java:61)
at org.apache.log4j.Logger.getLogger(Logger.java:39)
at log4j.Log4jExample.<clinit>(Log4jExample.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.flume.Event
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)
... 21 more
线程“main”Java结果中的异常:1
答案 0 :(得分:4)
您需要添加jar:flume-ng-sdk-1.3.1.jar。您可以从here
下载答案 1 :(得分:0)
似乎你没有在项目中包含Apache Flume。甚至可以从http://flume.apache.org/或Maven http://logging.apache.org/log4j/2.x/maven-artifacts.html
手动完成