gpt4 book ai didi

java - 从控制台启动 OSGI 时 Log4j2 不工作(在 Eclipse 中工作)

转载 作者:行者123 更新时间:2023-11-29 08:45:51 26 4
gpt4 key购买 nike

我有一个使用 log4j2 制作并在 eclipse 上运行的日志记录程序。我没有使用任何 xml 文件进行配置,而是以编程方式修改默认配置。我正在使用声明式服务在 OSGi 环境中进行开发。

当我从控制台运行 OSGi 并启动记录器包时,没有错误。但是当我启动另一个使用这个记录器包服务的包时,会显示一个错误:

Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException 

我把整个错误日志放在这里,以防它提供详细信息。因此, bundle 将无法解析。这个问题的原因可能是什么?

!SESSION 2014-08-21 23:05:27.381 -----------------------------------------------
eclipse.buildId=unknown
java.version=1.7.0_51
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=en_US
Command-line arguments: -console -consoleLog

!ENTRY comp4 4 0 2014-08-21 23:07:16.979
!MESSAGE [SCR] Error while trying to bind reference Reference[name = ILogger, interface = de.logger.ILogger, policy = static, cardinality = 1..1, target = null, bind = bindLoggerService, unbind = unbindLoggerService]
Details:
Problematic reference = Reference[name = ILogger, interface = de.logger.ILogger, policy = static, cardinality = 1..1, target = null, bind = bindLoggerService, unbind = unbindLoggerService]
of service component = comp4
component implementation class = de.comp4.finalTest
located in bundle with symbolic name = comp4
bundle location = file:\C:\Users\test2\plugins\comp4_1.0.0.jar
!STACK 0
java.lang.reflect.InvocationTargetException
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.internal.ds.model.ComponentReference.bind(ComponentReference.java:367)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bindReference(ServiceComponentProp.java:430)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bind(ServiceComponentProp.java:218)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:344)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:588)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:196)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:441)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:213)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:800)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:767)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
Caused by: java.lang.NoClassDefFoundError: javax/naming/NamingException
at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:75)
at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:99)
at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:29)
at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:63)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:125)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:80)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:72)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
at de.logger.tinylogger.TinyLogger.setClassName(TinyLogger.java:1097)
at de.comp4.finalTest.bindLoggerService(finalTest.java:27)
... 16 more
Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 28 more
Root exception:
java.lang.NoClassDefFoundError: javax/naming/NamingException
at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:75)
at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:99)
at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:29)
at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:63)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:125)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:80)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:72)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
at de.logger.tinylogger.TinyLogger.setClassName(TinyLogger.java:1097)
at de.comp4.finalTest.bindLoggerService(finalTest.java:27)
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.internal.ds.model.ComponentReference.bind(ComponentReference.java:367)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bindReference(ServiceComponentProp.java:430)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bind(ServiceComponentProp.java:218)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:344)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:588)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:196)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:441)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:213)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:800)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:767)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 28 more

!ENTRY comp4 4 0 2014-08-21 23:07:17.006
!MESSAGE [SCR] Error while trying to bind reference Reference[name = ILogger, interface = de.logger.ILogger, policy = static, cardinality = 1..1, target = null, bind = bindLoggerService, unbind = unbindLoggerService]
Details:
Problematic reference = Reference[name = ILogger, interface = de.logger.ILogger, policy = static, cardinality = 1..1, target = null, bind = bindLoggerService, unbind = unbindLoggerService]
of service component = comp4
component implementation class = de.comp4.finalTest
located in bundle with symbolic name = comp4
bundle location = file:\C:\test2\plugins\comp4_1.0.0.jar
!STACK 0
java.lang.reflect.InvocationTargetException
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.internal.ds.model.ComponentReference.bind(ComponentReference.java:367)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bindReference(ServiceComponentProp.java:430)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bind(ServiceComponentProp.java:218)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:344)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:588)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:196)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:441)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:213)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:800)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:767)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
Caused by: java.lang.NoClassDefFoundError: javax/naming/NamingException
at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:75)
at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:99)
at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:29)
at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:63)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:125)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:80)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:72)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
at de.logger.tinylogger.TinyLogger.setClassName(TinyLogger.java:1097)
at de.comp4.finalTest.bindLoggerService(finalTest.java:27)
... 16 more
Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 28 more
Root exception:
java.lang.NoClassDefFoundError: javax/naming/NamingException
at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:75)
at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:99)
at org.apache.logging.log4j.core.config.NullConfiguration.<init>(NullConfiguration.java:29)
at org.apache.logging.log4j.core.LoggerContext.<clinit>(LoggerContext.java:63)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(ClassLoaderContextSelector.java:218)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:125)
at org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(ClassLoaderContextSelector.java:80)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:72)
at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:37)
at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:473)
at de.logger.tinylogger.TinyLogger.setClassName(TinyLogger.java:1097)
at de.comp4.finalTest.bindLoggerService(finalTest.java:27)
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.internal.ds.model.ComponentReference.bind(ComponentReference.java:367)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bindReference(ServiceComponentProp.java:430)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.bind(ServiceComponentProp.java:218)
at org.eclipse.equinox.internal.ds.model.ServiceComponentProp.build(ServiceComponentProp.java:344)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponent(InstanceProcess.java:588)
at org.eclipse.equinox.internal.ds.InstanceProcess.buildComponents(InstanceProcess.java:196)
at org.eclipse.equinox.internal.ds.Resolver.buildNewlySatisfied(Resolver.java:441)
at org.eclipse.equinox.internal.ds.Resolver.enableComponents(Resolver.java:213)
at org.eclipse.equinox.internal.ds.SCRManager.performWork(SCRManager.java:800)
at org.eclipse.equinox.internal.ds.SCRManager$QueuedJob.dispatch(SCRManager.java:767)
at org.eclipse.equinox.internal.ds.WorkThread.run(WorkThread.java:89)
at org.eclipse.equinox.internal.util.impl.tpt.threadpool.Executor.run(Executor.java:70)
Caused by: java.lang.ClassNotFoundException: javax.naming.NamingException
at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:513)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:429)
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:417)
at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:107)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 28 more

!ENTRY org.eclipse.equinox.ds 4 0 2014-08-21 23:07:17.037
!MESSAGE The component was not built because some of its references could not be bound. The component is Component[
name = comp4
activate = activate
deactivate = deactivate
modified =
configuration-policy = optional
factory = null
autoenable = true
immediate = true
implementation = de.comp4.finalTest
state = Unsatisfied
properties =
serviceFactory = false
serviceInterface = null
references = {
Reference[name = ILogger, interface = de.logger.ILogger, policy = static, cardinality = 1..1, target = null, bind = bindLoggerService, unbind = unbindLoggerService]
}
located in bundle = comp4_1.0.0 [18]
]

!ENTRY org.eclipse.equinox.ds 4 0 2014-08-21 23:07:17.041
!MESSAGE The component was not built because some of its references could not be bound. The component is Component[
name = comp4
activate = activate
deactivate = deactivate
modified =
configuration-policy = optional
factory = null
autoenable = true
immediate = true
implementation = de.comp4.finalTest
state = Unsatisfied
properties =
serviceFactory = false
serviceInterface = null
references = {
Reference[name = ILogger, interface = de.logger.ILogger, policy = static, cardinality = 1..1, target = null, bind = bindLoggerService, unbind = unbindLoggerService]
}
located in bundle = comp4_1.0.0 [18]
]

编辑:

我已经在一个简单的设置中尝试了它,只使用 LogManager.getLogger() 没有配置代码(保留为默认值),但结果仍然相同。只有当我没有调用包含“LogManager.getLogger()”的方法时,包含 Log4j2 的包才会解析。

....Inside logger...
private static Logger m_Logger;
public void setClassName(String className)
{
//Logger m_Logger = LogManager.getLogger(className);
Logger m_Logger = LogManager.getLogger();
m_Logger.error("Logger program working");
}
....Inside consuming bundle...
protected void OSGiLoggerBind (OSGiLogger myLogger)
{
m_LoggerService = myLogger;
m_LoggerService.setClassName(OSGiLoggerTest.class.getName());
}

最佳答案

这实际上是一个错误。 LOG4J2 在 OSGi 环境中有类加载器问题,如 here同样也是here .

我之前使用的是下载版apache-log4j-2.0-rc2-bin。但是现在有一个新版本here apache-log4j-2.0.2-bin 运行在OSGi环境下。但是为了正确解析带有 LOG4j2 的包,我必须导入“org.osgi.framework.wiring”。

它仍然向我显示错误“Could not reconfigure JMX java.lang.NoClassDefFoundError: javax/management/ObjectName...”,我仍然需要找到解决方案,但至少它在 OSGi 环境中运行从控制台启动。

关于java - 从控制台启动 OSGI 时 Log4j2 不工作(在 Eclipse 中工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25436422/

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