Skip to content

Resolving the "com.fasterxml.jackson.core" packages not found issue, when enabling the JSON format logs. #1067

@janithcmw

Description

@janithcmw

In default behaviour, when the JSON log format is enabled with the following configurations in the "log4j2.xml" file, the below exception can be observed.
Configuration

<Configuration>
    <Appenders>
        <Console name="CARBON_CONSOLE" target="SYSTEM_OUT">
          <JSONLayout compact="true" eventEol="true"/>
        </Console>
...
...
...

Exception

SEVERE {org.wso2.carbon.launcher.Main main} - Exception in org.ops4j.pax.logging.log4j2.internal.Activator.start() of bundle org.ops4j.pax.logging.pax-logging-log4j2. 
java.lang.RuntimeException: Exception in org.ops4j.pax.logging.log4j2.internal.Activator.start() of bundle org.ops4j.pax.logging.pax-logging-log4j2.
	at org.wso2.carbon.launcher.CarbonServer.start(CarbonServer.java:94)
	at org.wso2.carbon.launcher.Main.main(Main.java:84)
Caused by: org.osgi.framework.BundleException: Exception in org.ops4j.pax.logging.log4j2.internal.Activator.start() of bundle org.ops4j.pax.logging.pax-logging-log4j2.
	at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:795)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:724)
	at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:932)
	at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:309)
	at org.eclipse.osgi.container.Module.doStart(Module.java:581)
	at org.eclipse.osgi.container.Module.start(Module.java:449)
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:383)
	at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:402)
	at org.wso2.carbon.launcher.CarbonServer.loadInitialBundles(CarbonServer.java:242)
	at org.wso2.carbon.launcher.CarbonServer.start(CarbonServer.java:83)
	... 1 more
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/ser/FilterProvider
	at org.apache.logging.log4j.core.layout.JsonLayout.<init>(JsonLayout.java:896)
	at org.apache.logging.log4j.core.layout.JsonLayout$Builder.build(JsonLayout.java:839)
	at org.apache.logging.log4j.core.layout.JsonLayout$Builder.build(JsonLayout.java:813)
	at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:952)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:892)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:884)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:508)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:232)
	at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:244)
	at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:545)
	at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:261)
	at org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.doUpdate(PaxLoggingServiceImpl.java:209)
	at org.ops4j.pax.logging.log4j2.internal.PaxLoggingServiceImpl.updated(PaxLoggingServiceImpl.java:154)
	at org.ops4j.pax.logging.log4j2.internal.Activator.start(Activator.java:152)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:774)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$3.run(BundleContextImpl.java:1)
	at java.security.AccessController.doPrivileged(Native Method)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:767)
	... 10 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.ser.FilterProvider cannot be found by org.ops4j.pax.logging.pax-logging-log4j2_1.10.0
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:448)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:361)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:353)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 30 more

The possible cause for this issue is the bundle "org.ops4j.pax.logging.pax-logging-log4j2_1.10.0" has been launched before launching the bundle which contains the "com.fasterxml.jackson.databind.ser.FilterProvide" method.
As solution the following entries were made in the "launch.properties" file(resides in /conf//osgi directory) and changed the bundle launching order.

carbon.initial.osgi.bundles=\
  file\:plugins/com.fasterxml.jackson.core.jackson-core_2.9.6.jar@1\:true,\
  file\:plugins/com.fasterxml.jackson.core.jackson-annotations_2.9.6.jar@1\:true,\
  file\:plugins/com.fasterxml.jackson.core.jackson-databind_2.9.6.jar@1\:true 

So shall we appy the bundle launching order as above as an improvement to the product?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions