繁体   English   中英

尝试在插件类型项目中添加log4j。 错误:java.lang.NoClassDefFoundError:org / apache / log4j / PropertyConfigurator

[英]Trying to add log4j in plugin type project. Error : java.lang.NoClassDefFoundError: org/apache/log4j/PropertyConfigurator

我试图在插件项目中添加Log4j.jar以进行日志记录。 我通过使用构建路径->添加外部jar添加了log4j jar。 之后,我尝试运行插件项目,但出现错误

java.lang.NoClassDefFoundError:org / apache / log4j / PropertyConfigurator。

如果我使用java main方法运行相同的代码,它将正常工作。

public HHLogger(Object className) {
    DateTimeFormatter df  = DateTimeFormatter.ofPattern("ddMMYYYY");
    System.setProperty("filename", df.format(LocalDate.now()));
    PropertyConfigurator.configure(".\\resources\\log4j.properties");
    logger = Logger.getLogger(className.getClass());
}



public static void main(String args[]) {
    DateTimeFormatter df  = DateTimeFormatter.ofPattern("ddMMYYYY");
    System.setProperty("filename", df.format(LocalDate.now()));
    PropertyConfigurator.configure(".\\resources\\log4j.properties");
    logger = Logger.getLogger(HHLogger.class);
    logger.info(" 999 Welcom");

}

java.lang.NoClassDefFoundError:com.americanexpress.connecthotelforgbt.utility.HHLogger。(HHLogger.java:22)上的org / apache / log4j / PropertyConfigurator在com.americanexpress.connecthotelforgbt.parsers.OhhRqRsParser。(OhRq com.americanexpress.connecthotelforgbt.listener.CommandModificationService.process(CommandModificationService.java:102)处的com.americanexpress.connecthotelforgbt.DataIntelliSense.java命令(DataIntelliSense.java:322)com.sabre.edge.cf.core.executors.PublicServiceExecutor。在org.jbpm.graph.node.Decision.execute(Decision.java:85)在org.jbpm.graph.def.Node.enter(Node.java:314)上确定(PublicServiceExecutor.java:143) org.jbpm.graph.def.Node.leave(Node.java:389)上的.graph.def.Transition.take(Transition.java:151)org.jbpm.graph.node.StartState.leave(StartState.java) :70),位于org.jbpm.graph.exe.Token.signal(Token.java:192),位于org.jbpm.graph.exe.Token.signal(Token.java:140)。 ProcessInstance.signal(ProcessInstance.java:2 71)在com.sabre.edge.cf.core.SRWRuntime.executeWorkflow(SRWRuntime.java:238)在com.sabre.edge.cf.core.SRWRuntime.executeWorkflow(SRBRuntime.java:238)在com.sabre.edge.cf.core.flow.JBPMFlowExecutor.execute(JBPMFlowExecutor.java:45) com.sabre.edge.cf.emu.bridge.EmulatorBridge.processServiceContext(EmulatorBridge.java:198)处的com.sabre.edge.cf.emu.edge.cf.core.SRWRuntime.process(SRWRuntime.java:173) com.sabre.stn.emulator.core.bridge.BridgeFilter.preSend(BridgeFilter.java:80)的com.sabre.stn.emulator.basic.model.BasicEmulatorModel的.bridge.EmulatorBridge.updateCommand(EmulatorBridge.java:87) com.sabre.stn.emulator.basic.model.BasicEmulatorModel.sendMessage(BasicEmulatorModel.java:3596)的.sendPreProcess(BasicEmulatorModel.java:3737)com.sabre.stn.emulator.basic.model.BasicEmulatorModel.doEnter(BasicEmulator .java:3516)at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.enter(BasicEmulatorModel.java:1749)at com.sabre.stulator.basic.Basic.BasicEmulator.enter(BasicEmulator.java:1979) com.sabre.stn.emulator.core.EmuManager.emptyT com.sabre.stn.emulator.core.KeysToScreenThread.run(KeysToScreenThread.java:78)处的heKeyBuffer(EmuManager.java:1132)原因:org.eclipse处的java.lang.ClassNotFoundException:org.apache.log4j.PropertyConfigurator。 org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)处的osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506)在org.eclipse.osgi.internal.loader.BundleLoader处。位于org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)的findClass(BundleLoader.java:410),位于java.lang.ClassLoader.loadClass(Unknown Source)的... 26更多

错误消息很清楚,找不到PropertyConfigurator的类文件,请确保类文件PropertyConfigurator在您的类路径中,如果在jar文件中,则同样适用。 它表明PropertyConfigurator在编译时找到,但在运行时找不到。 也许您只需要将其添加到类路径中即可。

请参阅这对您有帮助: 如何解决java.lang.NoClassDefFoundError?

ps:如果两个类在同一个文件中,则不能这样做,因为两者都是公共的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM