gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 10:30:02 24 4
gpt4 key购买 nike

我正在尝试在 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)

我需要做什么才能让日志记录在 RCP 应用程序中运行而不从我的 IDE 中启动它?

最佳答案

听起来 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。

关于java - 如何在 eclipse-rcp 应用程序中使用 org.apache.logging.log4j.jul.LogManager?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43759123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com