如何在eclipse-rcp应用程序中使用org.apache.logging.log4j.jul.LogManager?

时间:2017-05-03 11:44:02

标签: java eclipse logging eclipse-rcp log4j2

我正在尝试在eclipse rcp应用程序中使用log4j2 LogManager。 我有

  

-Djava.util.logging.manager = org.apache.logging.log4j.jul.LogManager

设置为启动参数。从我的eclipse IDE中启动rcp应用程序一切都按预期工作。但是一旦我作为独立的应用程序启动它,日志记录将无法正常工作。

可能的提示可能是来自客户端控制台的以下堆栈跟踪:

Could not load Logmanager "org.apache.logging.log4j.jul.LogManager"
java.lang.ClassNotFoundException: org.apache.logging.log4j.jul.LogManager
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at org.eclipse.core.runtime.internal.adaptor.ContextFinder.loadClass(ContextFinder.java:131)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.util.logging.LogManager$1.run(Unknown Source)
        at java.util.logging.LogManager$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.util.logging.LogManager.<clinit>(Unknown Source)
        at java.util.logging.Logger.demandLogger(Unknown Source)
        at java.util.logging.Logger.getLogger(Unknown Source)
        at org.apache.felix.gogo.runtime.threadio.ThreadIOImpl.<clinit>(ThreadIOImpl.java:30)
        at org.apache.felix.gogo.runtime.activator.Activator.start(Activator.java:75)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
        at org.eclipse.equinox.console.command.adapter.Activator.startBundle(Activator.java:248)
        at org.eclipse.equinox.console.command.adapter.Activator.start(Activator.java:237)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711)
        at java.security.AccessController.doPrivileged(Native Method)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702)
        at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683)
        at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381)
        at org.eclipse.osgi.framework.internal.core.AbstractBundle.start(AbstractBundle.java:300)
        at org.eclipse.osgi.framework.internal.core.ConsoleManager.checkForConsoleBundle(ConsoleManager.java:215)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:297)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1438)

如果不在我的IDE中启动日志记录而在RCP应用程序中运行日志记录,我需要做什么?

1 个答案:

答案 0 :(得分:1)

听起来eclipse意识到你对这个类的依赖,并且能够将它添加到类路径中。你需要的是一种在eclipse之外运行它时将依赖项添加到类路径的方法。要解决此问题,请确保类org.apache.logging.log4j.jul.LogManager位于类路径中。这可以使用-cp和jar文件的路径来完成。例如,如果你有一个类com.org.Main,你正试图运行。

java -cp your.jar:log4j-jul-2.3.jar com.org.Main

your.jar是包含你的应用程序的jar,log4j-jul-2.3.jar是包含缺少的类的jar。