Unable to get javax.mail to be found by package

141 Views Asked by At

I've written a program that uses log4j and it set to use the SMTPAppender at Error/Fatal level

   <SMTP name="ErrorMail" subject="iMCtoOVO ERROR" to="[email protected]" from="[email protected]" smtpHost="clientgateway.client.com" smtpPort="25" bufferSize="100">
    <ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="DENY"/>
    </SMTP>

It was working fine with standard Oracle Java, but since switching to OpenJDK, due to licensing, installed with the Microsoft installer, I have not been able to get it to work.

2022-09-15 14:52:15,568 main ERROR Could not create plugin of type class org.apacche.logging.log4j.core.appender.SmtpAppender for element SMTP: java.lang.NoClassDefFoundError: javax/mail/MessagingException java.lang.NoClassDefFoundError: javax/mail/MessagingException

Under Oracle Java, I had only been able to get this to work by putting the javax.mail.jar in the "ext" folder. I can find no such location now on this system. I have tried putting the path in the manifest Class-Path, removing Class-Path from the Manifest and specifying the location by java -cp (see below in case I've lost my ever loving mind) in various formats (e.g. quoted, \ and / absolute and relative path, wild card etc), I have rebuilt the runnable JAR with all necessary packages built in (Eclipse IDE) and I am out of ideas.

java -cp G:\iMCAlarmParse\lib\javax.mail.jar -Dlog4j.configurationFile=file:/g:/iMCAlarmParse/conf/log4j2-dev.xml -Dimctoovo.WorkPath=g:/imcAlarmParse/ -jar iMCAlarmParse-dev.jar 

I'm sure it's something amazingly dumb I'm missing in the stack trace but I'm at my wits end.

For reference: openjdk 17.0.4.1 2022-08-12 LTS OpenJDK Runtime Environment Microsoft-40354 (build 17.0.4.1+1-LTS) OpenJDK 64-Bit Server VM Microsoft-40354 (build 17.0.4.1+1-LTS, mixed mode, sharing)

Thanks in advance.

1

There are 1 best solutions below

0
cyberbrain On

Probably you are adding an outdated dependency, try

javax.mail:javax.mail-api:1.6.2

instead. You could use https://mvnrepository.com/artifact/javax.mail/javax.mail-api to get the binary, search for different versions, or try to switch to its successor jakarta.mail-api instead. (But this requires updates to the software as the package names changed.)