Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassNotFoundException when using custom appenders in OSGi projects #72

Open
simonzn opened this issue Mar 13, 2024 · 0 comments · May be fixed by #73
Open

ClassNotFoundException when using custom appenders in OSGi projects #72

simonzn opened this issue Mar 13, 2024 · 0 comments · May be fixed by #73

Comments

@simonzn
Copy link

simonzn commented Mar 13, 2024

Due to classpath separation in OSGi based projects, loading of custom Appenders fails with e.g.

log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: ch.sbb.rcs.common.logging.LazyRollingFileAppender cannot be found by org.apache.log4j_1.2.25
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:541)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:536)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:416)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:168)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:375)
	at org.apache.log4j.helpers.Loader.loadClass(Loader.java:159)
	at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:240)
	at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:174)
	at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.java:189)
	at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurator.java:492)
	at org.apache.log4j.xml.DOMConfigurator.parseCategory(DOMConfigurator.java:415)
	at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:932)
	at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:808)
	at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:721)
	at org.apache.log4j.xml.DOMConfigurator.configure(DOMConfigurator.java:839)
       [...]

The manifest should define a buddy policy to enable buddy class loading, as described in Context Class Loader Enhancements.

I'd suggest to add Eclipse-BuddyPolicy: registered. Then, the issue above is fixed by adding Eclipse-RegisterBuddy: org.apache.log4j to the bundle that provides the custom appender.

simonzn added a commit to simonzn/reload4j that referenced this issue Mar 13, 2024
Adds the buddy policy 'registered' to the
manifest so that custom appenders provided
by OSGi bundles can be loaded via buddy
class loading.

The providing bundle must define a
corresponding Eclipse-RegisterBuddy header.

Closes qos-ch#72
@simonzn simonzn linked a pull request Mar 13, 2024 that will close this issue
simonzn added a commit to simonzn/reload4j that referenced this issue Mar 13, 2024
Adds the buddy policy 'registered' to the
manifest so that custom appenders provided
by OSGi bundles can be loaded via buddy
class loading.

The providing bundle must define a
corresponding Eclipse-RegisterBuddy header.

Closes qos-ch#72
simonzn added a commit to simonzn/reload4j that referenced this issue Apr 16, 2024
Adds the buddy policy 'registered' to the
manifest so that custom appenders provided
by OSGi bundles can be loaded via buddy
class loading.

The providing bundle must define a
corresponding Eclipse-RegisterBuddy header.

Closes qos-ch#72

Signed-off-by: Simon Zilliken <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant