2017-05-03 56 views
1

我想在eclipse rcp應用程序中使用log4j2 LogManager。 我有如何在eclipse-rcp應用程序中使用org.apache.logging.log4j.jul.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) 

什麼我需要做的就是登錄RCP應用程序運行沒有從我的IDE中啓動它?

回答

0

聽起來像eclipse知道你對這個類的依賴,並且能夠將它添加到你的類路徑中。當你在eclipse之外運行時,你需要的是一種將依賴添加到classpath的方法。要解決此問題,請確保類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是包含應用程序和log4j的-JUL-2.3.jar罐子被包含丟失類的罐子。

相關問題