Logback SMTP Appender under SLF4J + java modular

50 Views Asked by At

I've been trying to setup SMTP Appender in Logback's configuration and I keep receiving the following error:

java.lang.IllegalAccessError:superclass access check failed: class ch.qos.logback.core.net.LoginAuthenticator (in module ch.qos.logback.core) cannot access class javax.mail.Authenticator (in unnamed module <module>) because module ch.qos.logback.core does not read unnamed module <module>

This is the SMTP Appender configuration:

<appender name="SMTP" class="ch.qos.logback.classic.net.SMTPAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d{dd/MM/yyyy HH:mm:ss} | %-5level | %logger{0} | %thread | %msg%n</pattern>
        </layout>
        <smtpHost>smtp_server</smtpHost>
        <smtpPort>port</smtpPort>
        <username>username</username>
        <password>password</password>
        <STARTTLS>true</STARTTLS>
        <SSL>true</SSL>
        <from>sender</from>
        <to>recipient</to>
        <subject>subject</subject>
    </appender>

Given that my application is a gradle project, I declared the following dependencies:

dependencies {
    implementation 'javax.activation:activation:1.1.1'
    implementation 'javax.mail:mail:1.4'
}

From the official documentation:

The SMTPAppender relies on the JavaMail API. It has been tested with JavaMail API version 1.4. The JavaMail API requires the JavaBeans Activation Framework package. You can download the JavaMail API and the JavaBeans Activation Framework from their respective websites. Make sure to place these two jar files in the classpath before trying the following examples.

This is how my application is being instantiated:

CLASSPATH=$APP_HOME/lib/mail-1.4.jar:$APP_HOME/lib/activation-1.1.1.jar:$APP_HOME/etc
MODULE_PATH=$APP_HOME/lib/application.jar:<other_dependencies>

java $DEFAULT_JVM_OPTS $JAVA_OPTS -classpath "\"$CLASSPATH\"" --module-path "\"$MODULE_PATH\"" --module <module>/<main_class> "$APP_ARGS"

I think worth to mention that my application is a java 11 implementation, so it uses java modular and runs Logback under SLF4J.

0

There are 0 best solutions below