简体   繁体   English

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

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

I'm trying to send an email through Java Mail API and it works fine on my laptop.我正在尝试通过 Java Mail API 发送电子邮件,它在我的笔记本电脑上运行良好。 When I'm doing exactly the same in Heroku, I'm getting this:当我在 Heroku 中做同样的事情时,我得到了这个:

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 :这是我在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?我想 Heroku JDK 中还有另一个版本的 Java Mail API,它没有这个构造函数......这怎么能解决?

By default, Java apps running on latest Heroku stack use OpenJDK 8.默认情况下,在最新 Heroku 堆栈上运行的 Java 应用程序使用 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 .您的问题似乎与实际的 JVM 实现无关,而是由于 classpath 中缺少smtp-1.5.1.jar To be sure to load correctly TraceInputStream try this :为了确保正确加载 TraceInputStream 试试这个:

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

You've mixed different versions of the API and implementation;您混合了不同版本的 API 和实现; don't do that.不要那样做。 For that matter, you only need the com.sun.mail:javax.mail dependency.就此而言,您只需要 com.sun.mail:javax.mail 依赖项。 If Heroku isn't providing it in the runtime environment, you'll need to package it in your application.如果 Heroku 没有在运行时环境中提供它,您需要将它打包到您的应用程序中。 Make sure the JavaMail jar file is ending up in the WEB-INF/lib directory of your application.确保 JavaMail jar 文件位于应用程序的 WEB-INF/lib 目录中。

I also faced the same issue.我也面临同样的问题。 It was because I don't have the class TraceInputStream inside the library.这是因为我在库中没有 TraceInputStream 类。 I simply downgrade libraries to 1.4.4 and it worked.我只是将库降级到 1.4.4 并且它起作用了。

    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>smtp</artifactId>
        <version>1.4.4</version>
    </dependency>
    <dependency>
        <groupId>com.sun.mail</groupId>
        <artifactId>mailapi</artifactId>
        <version>1.4.4</version>
    </dependency>

Getting reference from @Osanda Deshan.从@Osanda Deshan 获取参考。 Adding below gradle dependencies Worked for me.添加以下gradle依赖项对我有用。

    implementation 'javax.mail:javax.mail-api:1.4.4'
    implementation 'javax.mail:mail:1.4.4'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NoSuchMethodError: com.sun.mail.util.TraceInputStream Tomcat9 jdk1.8.0_281 - NoSuchMethodError: com.sun.mail.util.TraceInputStream Tomcat9 jdk1.8.0_281 java.lang.NoSuchMethodError: com.sun.istack.localization.LocalizableMessageFactory - java.lang.NoSuchMethodError: com.sun.istack.localization.LocalizableMessageFactory java.lang.ClassNotFoundException:com.sun.mail.util.MessageRemovedIOException - java.lang.ClassNotFoundException: com.sun.mail.util.MessageRemovedIOException java.lang.NoSuchMethodError的原因:com.sun.jna.Native.register(Ljava / lang / String;)V - Cause of java.lang.NoSuchMethodError: com.sun.jna.Native.register(Ljava/lang/String;)V java.lang.NoSuchMethodError:com.google.common.util.concurrent.MoreExecutors.platformThreadFactory()Ljava / util / concurrent / ThreadFactory; - java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.platformThreadFactory()Ljava/util/concurrent/ThreadFactory; java.lang.NoSuchMethodError:com.sun.xml.ws.api.pipe.ClientTubeAssemblerContext.getPortInfo()Lcom / sun / xml / ws / api / client / WSPortInfo; - java.lang.NoSuchMethodError : com.sun.xml.ws.api.pipe.ClientTubeAssemblerContext.getPortInfo()Lcom/sun/xml/ws/api/client/WSPortInfo; java.lang.NoSuchMethodError: com.wm.util.Strings.isBlank(Ljava/lang/String;)Z - java.lang.NoSuchMethodError: com.wm.util.Strings.isBlank(Ljava/lang/String;)Z java.lang.NoSuchMethodError: '布尔值 com.sun.prism.ResourceFactory.isDisposed()' JavaFX - java.lang.NoSuchMethodError: 'boolean com.sun.prism.ResourceFactory.isDisposed()' JavaFX java.lang.NoSuchMethodError:sun.security.ssl.SupportedEllipticCurvesExtension - java.lang.NoSuchMethodError: sun.security.ssl.SupportedEllipticCurvesExtension 修复 java.lang.NoSuchMethodError: com.amazonaws.util.StringUtils.trim - Fixing java.lang.NoSuchMethodError: com.amazonaws.util.StringUtils.trim
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM