logback. class not found exception

3.9k views Asked by At

I am trying to add a DB appender into my logback configuration. Here is the part of the logback.xml file related to the issue:

<appender name="db" class="src.main.java.database.SqliteLogbackAppender">
    <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
        <driverClass>org.sqlite.JDBC</driverClass>
        <url>jdbc:sqlite:/home/db/logger.db</url>
    </connectionSource>
</appender>

The thing is, I use a custom appender, which is located in my scr.main.java...etc folder, but not in logback-classic library

When I run my application, I get the following error:

    09:02:06,682 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@31:78 - ActionException in Action for tag [appender] ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type src.main.java.database.SqliteLogbackAppender
        at ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type src.main.java.database.SqliteLogbackAppender
        at      at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:76)
        at      at ch.qos.logback.core.joran.spi.Interpreter.callBeginAction(Interpreter.java:269)
        at      at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:145)
        at      at ch.qos.logback.core.joran.spi.Interpreter.startElement(Interpreter.java:128)
        at      at ch.qos.logback.core.joran.spi.EventPlayer.play(EventPlayer.java:50)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:155)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:142)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:103)
        at      at ch.qos.logback.core.joran.GenericConfigurator.doConfigure(GenericConfigurator.java:53)
        at      at ch.qos.logback.classic.util.ContextInitializer.configureByResource(ContextInitializer.java:75)
        at      at ch.qos.logback.classic.util.ContextInitializer.autoConfig(ContextInitializer.java:150)
        at      at org.slf4j.impl.StaticLoggerBinder.init(StaticLoggerBinder.java:84)
        at      at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:55)
        at      at org.slf4j.LoggerFactory.bind(LoggerFactory.java:149)
        at      at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:124)
        at      at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:390)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:340)
        at      at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:361)
        at      at interaction.Commander.<clinit>(Commander.java:14)
        at      at servlets.ExecuteServlet.<clinit>(ExecuteServlet.java:24)
        at      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at      at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at      at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:120)
        at      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1041)
        at      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:770)
        at      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133)
        at      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475)
        at      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
        at      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
        at      at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:651)
        at      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
        at      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
        at      at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498)
        at      at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at      at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796)
        at      at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1374)
        at      at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at      at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at      at java.lang.Thread.run(Thread.java:748)
Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type src.main.java.database.SqliteLogbackAppender
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:69)
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:45)
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:34)
        at      at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:52)
        at      ... 43 common frames omitted
Caused by: java.lang.ClassNotFoundException: src.main.java.database.SqliteLogbackAppender
        at      at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1269)
        at      at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
        at      at ch.qos.logback.core.util.OptionHelper.instantiateByClassNameAndParameter(OptionHelper.java:56)
        at      ... 46 common frames omitted

However, when I write classpath on logback.xml configuration, I am able to access file with IntellijIdea IDE interface (by clicking ctrl+left_mouse_button), so I believe there are no typos.

Regards.

1

There are 1 answers

1
Nate On BEST ANSWER

Be sure to use the fully qualified class name, including package, for your appender in the XML. Do not specify the path to the class.

"src.main.java.database.SqliteLogbackAppender" seems to include the Maven folders (src/main/java) and therefore likely isn't the actual class name.

Perhaps you meant just 'database.SqliteLogbackAppender'?