Issue
I need a little help to understand an error which, I hope, will be easy to solve for experienced developper :)
I developp a Java EE application, I just reinstalled my server (ubuntu) and now my application cannot send e-mail.
From my local environnement I still can send e-mail (Eclipse, Tomcat9, jdk1.8.0_281). But from my server I get the following error:
java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream.<init>(Ljava/io/InputStream;Lcom/sun/mail/util/MailLogger;)V
at com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:2016)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1936)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654)
I cannot understand because my server also run tomcat9 and I specialy installed jdk1.8.0_281. (I installed the jdk and set JAVA_HOME=/usr/lib/jvm/jdk1.8.0_281 in /etc/default/tomcat9)
I export my project from Eclipse, it should have all the lib, and I cannot see what is different in the two environnement.
Do you have any suggestion or solution? Thank you, and I wish you a happy new year !
Adrien
Edit following Matt advise So I added -verbose:class to java parameter, both in my local dev environnement et on my server, and look for intersting classes for our purpose. As you guessed there is a gap between the two environments, here :
On Local PC:
[Loaded com.sun.mail.util.TraceInputStream from file:/D:/EclipseWorkspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/wtpwebapps/MyApp/WEB-INF/lib/javax.mail.jar]
On Ubuntu Server
[2022-01-03 20:21:28] [info] [Loaded com.sun.mail.util.TraceInputStream from file:/var/lib/tomcat9/webapps/MyApp%23%232.02/WEB-INF/lib/mailapi.jar]
Solution
Without knowing your dependencies it's difficult to say what the issue is, but your version of Java is irrelevant for this issue.
Most likely the compiled and deployed version of your app is using a different version of JavaMail or another dependency than you have locally, and this deployed version doesn't have that method.
Add the Java option -verbose:class
and it'll tell you what classes are being loaded, then grep for TraceInputStream
or SMTPTransport
. Do the same on your server and locally and compare the versions.
Answered By - Matt
Answer Checked By - Katrina (JavaFixing Volunteer)