Java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream

I am trying to send an email through the Java Mail API and it works fine on my laptop. When I do the same in Heroku, I get the following:

java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream.(Ljava/io/InputStream;Lcom/sun/mail/util/MailLogger;)V at com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:2014) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1936) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654) at javax.mail.Service.connect(Service.java:291) at ... 

Here is what I have in pom.xml :

  <dependency> <groupId>javax.mail</groupId> <artifactId>mailapi</artifactId> <version>1.4.3</version> <scope>provided</scope> </dependency> <dependency> <groupId>com.sun.mail</groupId> <artifactId>javax.mail</artifactId> <version>1.5.3</version> <scope>runtime</scope> </dependency> 

I assume that there is another version of the Java Mail API inside the Heroku JDK that does not have this constructor ... How can this be fixed?

+5
source share
2 answers

By default, Java applications running on Heroku's latest stack use OpenJDK 8.

Your problem is not related to the actual implementation of the JVM, but rather due to the lack of smtp-1.5.1.jar in the classpath. To load TraceInputStream correctly, try the following:

 java.net.URL classUrl = this.getClass().getResource("com.sun.mail.util.TraceInputStream"); out.println(classUrl.getFile()); 
+2
source

You mixed different versions of the API and implementations; do not do this. In this case, you only need com.sun.mail: javax.mail dependency. If Heroku does not provide it at runtime, you will need to package it in your application. Make sure the JavaMail jar file ends in the WEB-INF / lib directory of your application.

+2
source

All Articles