I'm using simplejavamail in my Quarkus application. I have both the library and its batch-module included in my pom.xml:
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>8.12.4</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>batch-module</artifactId>
<version>8.12.4</version>
</dependency>
My code works fine in dev environment, but after building the native image, I get this error:
org.simplejavamail.internal.moduleloader.ModuleLoaderException: Batch module not found, make sure it is on the classpath (https://github.com/bbottema/simple-java-mail/tree/develop/modules/batch-module)
at org.simplejavamail.internal.moduleloader.ModuleLoader.loadModule(ModuleLoader.java:133)
at org.simplejavamail.internal.moduleloader.ModuleLoader.loadBatchModule(ModuleLoader.java:95)
at org.simplejavamail.mailer.internal.MailerGenericBuilderImpl.determineDefaultExecutorService(MailerGenericBuilderImpl.java:674)
at org.simplejavamail.mailer.internal.MailerGenericBuilderImpl.buildOperationalConfig(MailerGenericBuilderImpl.java:319)
at org.simplejavamail.mailer.internal.MailerImpl.<init>(MailerImpl.java:128)
at org.simplejavamail.mailer.internal.MailerRegularBuilderImpl.buildMailer(MailerRegularBuilderImpl.java:212)
I have tried registering the BatchModule class for reflection with no success:
import io.quarkus.runtime.annotations.RegisterForReflection;
import org.simplejavamail.internal.modules.BatchModule;
@RegisterForReflection(targets = {
BatchModule.class
})
public class LibReflectionRegister {
}
How do I fix this?
P.S. I don't know if this problem is related to this property I set to address another build error:
quarkus:
native:
additional-build-args: "--initialize-at-run-time=org.simplejavamail.internal.util.MiscUtil"
As you already noticed simplejavamail
is not supported by Quarkus and thus requires some extra configuration to make it work in native mode.
Looking at https://github.com/bbottema/simple-java-mail/blob/ac9a42997c062cdb8f48dfa112930cc1c8d04af1/modules/simple-java-mail/src/main/java/org/simplejavamail/internal/moduleloader/ModuleLoader.java#L75-L87 my understanding is that the code is using org.simplejavamail.internal.batchsupport.BatchSupport
to assess if the module is available or not. So you would need to register this class for reflection, but I am afraid this will only allow you to move past this error till you hit a different one.
Runtime initializing org.simplejavamail.internal.moduleloader.ModuleLoader
might be necessary as well.