logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonathan Hanba (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (LOG4J2-920) ClassNotFoundException for BundleContextSelector when initialising in an OSGi environment
Date Sun, 02 Aug 2015 21:34:05 GMT

    [ https://issues.apache.org/jira/browse/LOG4J2-920?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14651194#comment-14651194
] 

Jonathan Hanba commented on LOG4J2-920:
---------------------------------------

Running the OSGi Log4J 2.3.0 bundle in Felix OSGi Framework 4.4.1 results in this error as
noted in the original bug report.
--------------------------------------------------------------------------------
ERROR StatusLogger Unable to create context org.apache.logging.log4j.core.osgi.BundleContextSelector
java.lang.ClassNotFoundException: org.apache.logging.log4j.core.osgi.BundleContextSelector
not found by org.apache.logging.log4j.api [3]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)
	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:117)
	at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:136)
	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:163)
	at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:96)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:54)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:96)
	at com.ge.ip.systemtest2.osgi.example.Activator.<clinit>(Activator.java:18)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4362)
	at org.apache.felix.framework.Felix.activateBundle(Felix.java:2149)
	at org.apache.felix.framework.Felix.startBundle(Felix.java:2072)
	at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)
	at aQute.launcher.Launcher.update(Launcher.java:436)
	at aQute.launcher.Launcher.activate(Launcher.java:349)
	at aQute.launcher.Launcher.run(Launcher.java:238)
	at aQute.launcher.Launcher.main(Launcher.java:87)

ERROR StatusLogger Unable to create context org.apache.logging.log4j.core.osgi.BundleContextSelector
java.lang.ClassNotFoundException: org.apache.logging.log4j.core.osgi.BundleContextSelector
not found by org.apache.logging.log4j.api [3]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)
	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:117)
	at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:136)
	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:163)
	at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:96)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:54)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:96)
	at com.ge.ip.systemtest2.osgi.example.Activator.<clinit>(Activator.java:18)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4362)
	at org.apache.felix.framework.Felix.activateBundle(Felix.java:2149)
	at org.apache.felix.framework.Felix.startBundle(Felix.java:2072)
	at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)
	at aQute.launcher.Launcher.update(Launcher.java:436)
	at aQute.launcher.Launcher.activate(Launcher.java:349)
	at aQute.launcher.Launcher.run(Launcher.java:238)
	at aQute.launcher.Launcher.main(Launcher.java:87)

2015-08-02 15:57:21,251 WARN JNDI lookup class is not available because this JRE does not
support JNDI. JNDI string lookups will not be available, continuing configuration. java.lang.ClassNotFoundException:
org.apache.logging.log4j.core.lookup.JndiLookup not found by org.apache.logging.log4j.api
[3]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)
	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:117)
	at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:136)
	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:163)
	at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
	at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:92)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:104)
	at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:55)
	at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:374)
	at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:279)
	at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.<init>(ConsoleAppender.java:119)
	at org.apache.logging.log4j.core.appender.ConsoleAppender.newBuilder(ConsoleAppender.java:114)
	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.apache.logging.log4j.core.config.plugins.util.PluginBuilder.createBuilder(PluginBuilder.java:160)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:120)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:766)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:706)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:698)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:358)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:161)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:361)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:426)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:442)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
	at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:426)
	at com.ge.ip.systemtest2.osgi.example.Activator.<clinit>(Activator.java:18)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4362)
	at org.apache.felix.framework.Felix.activateBundle(Felix.java:2149)
	at org.apache.felix.framework.Felix.startBundle(Felix.java:2072)
	at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)
	at aQute.launcher.Launcher.update(Launcher.java:436)
	at aQute.launcher.Launcher.activate(Launcher.java:349)
	at aQute.launcher.Launcher.run(Launcher.java:238)
	at aQute.launcher.Launcher.main(Launcher.java:87)

2015-08-02 15:57:21,254 WARN JMX runtime input lookup class is not available because this
JRE does not support JMX. JMX lookups will not be available, continuing configuration. java.lang.ClassNotFoundException:
org.apache.logging.log4j.core.lookup.JmxRuntimeInputArgumentsLookup not found by org.apache.logging.log4j.api
[3]
	at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)
	at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
	at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Unknown Source)
	at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:117)
	at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:136)
	at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:163)
	at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
	at org.apache.logging.log4j.core.lookup.Interpolator.<init>(Interpolator.java:103)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.<init>(AbstractConfiguration.java:104)
	at org.apache.logging.log4j.core.config.DefaultConfiguration.<init>(DefaultConfiguration.java:55)
	at org.apache.logging.log4j.core.layout.PatternLayout$Builder.build(PatternLayout.java:374)
	at org.apache.logging.log4j.core.layout.PatternLayout.createDefaultLayout(PatternLayout.java:279)
	at org.apache.logging.log4j.core.appender.ConsoleAppender$Builder.<init>(ConsoleAppender.java:119)
	at org.apache.logging.log4j.core.appender.ConsoleAppender.newBuilder(ConsoleAppender.java:114)
	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.apache.logging.log4j.core.config.plugins.util.PluginBuilder.createBuilder(PluginBuilder.java:160)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:120)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:766)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:706)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:698)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:358)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:161)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:361)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:426)
	at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:442)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:138)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:147)
	at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:41)
	at org.apache.logging.log4j.LogManager.getContext(LogManager.java:175)
	at org.apache.logging.log4j.LogManager.getLogger(LogManager.java:426)
	at com.ge.ip.systemtest2.osgi.example.Activator.<clinit>(Activator.java:18)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
	at java.lang.reflect.Constructor.newInstance(Unknown Source)
	at java.lang.Class.newInstance(Unknown Source)
	at org.apache.felix.framework.Felix.createBundleActivator(Felix.java:4362)
	at org.apache.felix.framework.Felix.activateBundle(Felix.java:2149)
	at org.apache.felix.framework.Felix.startBundle(Felix.java:2072)
	at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:976)
	at aQute.launcher.Launcher.update(Launcher.java:436)
	at aQute.launcher.Launcher.activate(Launcher.java:349)
	at aQute.launcher.Launcher.run(Launcher.java:238)
	at aQute.launcher.Launcher.main(Launcher.java:87)
--------------------------------------------------------------------------------
Adjusting the pom.xml file in the log4j-api bundle to contain the following OSGi section addresses
the above exceptions. What's clearly missing from the original pom.xml is the OSGi specification
to import the Log4J OSGi package, which is the reason for the ClassNotFoundException. It's
simply not being imported, so the class is not found. The third exception listed above relates
to a ClassNotFoundException for class org.apache.logging.log4j.core.lookup.JndiLookup. Again,
the lookup package is simply not being imported, so the class is not found. The addition of
these two lines under the Import-Package section in the log4j-api pom.xml file clearly addresses
these two exceptions.
--------------------------------------------------------------------------------
<plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <configuration>
          <instructions>
            <Export-Package>org.apache.logging.log4j.*</Export-Package>
            <Import-Package>
			  org.apache.logging.log4j.core.osgi;resolution:=runtime,
			  org.apache.logging.log4j.core.lookup;resolution:=runtime,
              sun.reflect;resolution:=optional,
              *
            </Import-Package>
            <Bundle-Activator>org.apache.logging.log4j.util.Activator</Bundle-Activator>
          </instructions>
        </configuration>
      </plugin>
--------------------------------------------------------------------------------
As shown below, after log4j-api has been rebuilt with the Import-Package corrections to the
pom.xml file, Log4J clearly works without exceptions.
--------------------------------------------------------------------------------
16:21:50.677 [main] INFO  Hello World!


> ClassNotFoundException for BundleContextSelector when initialising in an OSGi environment
> -----------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-920
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-920
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 2.1
>         Environment: Apache Felix, Java 8
>            Reporter: Ludovic HOCHET
>         Attachments: LOG4J2-920.zip, patch.diff, patch2.diff, pom.xml
>
>
> When initialising Log4J2 in an Apache Felix environment, I get the following exception:

> ERROR StatusLogger Unable to create context org.apache.logging.log4j.core.osgi.BundleContextSelector
java.lang.ClassNotFoundException: org.apache.logging.log4j.core.osgi.BundleContextSelector
not found by org.apache.logging.log4j.api [78]
>     at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1556)
>     at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:77)
>     at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1993)
>     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
>     at java.lang.Class.forName0(Native Method)
>     at java.lang.Class.forName(Class.java:260)
>     at org.apache.logging.log4j.util.LoaderUtil.loadClass(LoaderUtil.java:117)
>     at org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(LoaderUtil.java:136)
>     at org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(LoaderUtil.java:163)
>     at org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(Loader.java:311)
>     at org.apache.logging.log4j.core.impl.Log4jContextFactory.createContextSelector(Log4jContextFactory.java:96)
>     at org.apache.logging.log4j.core.impl.Log4jContextFactory.<init>(Log4jContextFactory.java:54)
>     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
>     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
>     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>     at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
>     at java.lang.Class.newInstance(Class.java:438)
>     at org.apache.logging.log4j.LogManager.<clinit>(LogManager.java:96)
> [...]
> Due to a missing import of the org.apache.logging.log4j.core.osgi package in the API
OSGi metadata in its pom



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message