java.lang.NoSuchMethodError:com.sun.mail.util.TraceInputStream [英] java.lang.NoSuchMethodError: com.sun.mail.util.TraceInputStream

查看:2226
本文介绍了java.lang.NoSuchMethodError:com.sun.mail.util.TraceInputStream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过Java Mail API发送电子邮件,并且它在我的笔记本电脑上正常工作。当我在Heroku中完全一样的时候,我得到了这个:

  java.lang.NoSuchMethodError:com.sun .mail.util.TraceInputStream。(Ljava / io / InputStream; Lcom / sun / mail / util / MailLogger;)在com.sun.mail.smtp.SMTPTransport.initStreams(SMTPTransport.java:2014)$ V 

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 ...

以下是我在 pom.xml 中的内容:

 <依赖性> 
< groupId> javax.mail< / groupId>
< artifactId> mailapi< / artifactId>
< version> 1.4.3< / version>
< scope>提供< / scope>
< /依赖关系>
< dependency>
< groupId> com.sun.mail< / groupId>
< artifactId> javax.mail< / artifactId>
< version> 1.5.3< / version>
< scope>运行时< / scope>
< /依赖关系>

我猜Heroku JDK中有另一个版本的Java Mail API,它没有这个构造函数...如何解决这个问题?

解决方案

默认情况下,运行在最新Heroku堆栈上的Java应用程序使用OpenJDK 8。 p>

你的问题似乎与实际的JVM实现没有关系,而是由于缺少 smtp-1.5.1.jar 在classpath中。为确保正确加载TraceInputStream,请尝试以下操作:

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


I'm trying to send an email through Java Mail API and it works fine on my laptop. When I'm doing exactly the same in Heroku, I'm getting this:

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 guess there is another version of Java Mail API inside Heroku JDK, which doesn't have this constructor... How can this be fixed?

解决方案

By default, Java apps running on latest Heroku stack use OpenJDK 8.

Your problem does not seems related to the actual JVM implementation but rather due to the missing smtp-1.5.1.jar in classpath . To be sure to load correctly TraceInputStream try this :

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

这篇关于java.lang.NoSuchMethodError:com.sun.mail.util.TraceInputStream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆