0
votes

I am trying to add Log4j.jar in plugin project for logging purpose. I add the log4j jar by using build path->add external jar. After that I am trying to run the plugin project I get error

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

if I run the same code by using java main method it will working fine.

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: org/apache/log4j/PropertyConfigurator at com.americanexpress.connecthotelforgbt.utility.HHLogger.(HHLogger.java:22) at com.americanexpress.connecthotelforgbt.parsers.OhhRqRsParser.(OhhRqRsParser.java:104) at com.americanexpress.connecthotelforgbt.DataIntelliSense.upshellcommand(DataIntelliSense.java:322) at com.americanexpress.connecthotelforgbt.listener.CommandModificationService.process(CommandModificationService.java:102) at com.sabre.edge.cf.core.executors.PublicServiceExecutor.decide(PublicServiceExecutor.java:143) at org.jbpm.graph.node.Decision.execute(Decision.java:85) at org.jbpm.graph.def.Node.enter(Node.java:314) at org.jbpm.graph.def.Transition.take(Transition.java:151) at org.jbpm.graph.def.Node.leave(Node.java:389) at org.jbpm.graph.node.StartState.leave(StartState.java:70) at org.jbpm.graph.exe.Token.signal(Token.java:192) at org.jbpm.graph.exe.Token.signal(Token.java:140) at org.jbpm.graph.exe.ProcessInstance.signal(ProcessInstance.java:271) at com.sabre.edge.cf.core.flow.JBPMFlowExecutor.execute(JBPMFlowExecutor.java:45) at com.sabre.edge.cf.core.SRWRuntime.executeWorkflow(SRWRuntime.java:238) at com.sabre.edge.cf.core.SRWRuntime.process(SRWRuntime.java:173) at com.sabre.edge.cf.emu.bridge.EmulatorBridge.processServiceContext(EmulatorBridge.java:198) at com.sabre.edge.cf.emu.bridge.EmulatorBridge.updateCommand(EmulatorBridge.java:87) at com.sabre.stn.emulator.core.bridge.BridgeFilter.preSend(BridgeFilter.java:80) at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.sendPreProcess(BasicEmulatorModel.java:3737) at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.sendMessage(BasicEmulatorModel.java:3596) at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.doEnter(BasicEmulatorModel.java:3516) at com.sabre.stn.emulator.basic.model.BasicEmulatorModel.enter(BasicEmulatorModel.java:1749) at com.sabre.stn.emulator.basic.BasicEmulator.enter(BasicEmulator.java:1979) at com.sabre.stn.emulator.core.EmuManager.emptyTheKeyBuffer(EmuManager.java:1132) at com.sabre.stn.emulator.core.KeysToScreenThread.run(KeysToScreenThread.java:78) Caused by: java.lang.ClassNotFoundException: org.apache.log4j.PropertyConfigurator at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:506) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422) at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410) at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107) at java.lang.ClassLoader.loadClass(Unknown Source) ... 26 more

1

1 Answers

0
votes

The error message is clear, it can not find the class file of PropertyConfigurator make sure that the class file PropertyConfiguratoris in your classpath, or the same applies if it is in a jar file . it indicates, that PropertyConfigurator was found at compiletime but not at runtime. maybe you just have to add it to the classpath.

Please see this can help: How to solve java.lang.NoClassDefFoundError?

ps: if the two classes are on the same file, you can not do that, because both are public.