【问题标题】:ClassNotFoundException - AmazonSimpleEmailServiceClientBuilder on EC2 ubuntu instance [duplicate]ClassNotFoundException - EC2 ubuntu 实例上的 AmazonSimpleEmailServiceClientBuilder [重复]
【发布时间】:2018-03-18 01:15:05
【问题描述】:

我想在 AWS EC2 ubuntu 实例上的 java 应用程序中添加邮件发送功能。我的邮件地址已经在 SES 仪表板中注册并得到验证。 EC2 实例位于爱尔兰的欧盟西部地区,因此 AWS SES 应该可用,因为有文档。

我从 AWSJavaSDK 文档中获取了这个示例代码:

AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard().build();

SendEmailRequest request = new SendEmailRequest()
    .withSource("sender@example.com")
    .withDestination(
            new Destination().withToAddresses("recipient1@example.com", "recipient2@example.com").withCcAddresses("recipient3@example.com")
                    .withBccAddresses(new ArrayList()))
    .withMessage(
            new Message()
                    .withSubject(new Content().withData("Test email").withCharset("UTF-8"))
                    .withBody(
                            new Body()
                                    .withText(new Content().withData("This is the message body in text format.").withCharset("UTF-8"))))
                                    .withReplyToAddresses(new ArrayList()).withReturnPath("").withSourceArn("").withReturnPathArn("");

SendEmailResult response = client.sendEmail(request);

我还将此依赖项包含在我的 pom.xml 中:

    <dependency>
        <groupId>com.amazonaws</groupId>
        <artifactId>aws-java-sdk-ses</artifactId>
        <version>1.11.296</version>
    </dependency>

我得到的错误信息是:

线程“主”java.lang.NoClassDefFoundError 中的异常: com/amazonaws/services/simpleemail/AmazonSimpleEmailServiceClientBuilder

引起:java.lang.ClassNotFoundException: com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder

当我在本地启动我的应用程序时,只会出现找不到区域但查找类没有问题的异常。

为什么在 EC2 实例上找不到类 AmazonSimpleEmailServiceClientBuilder

【问题讨论】:

    标签: java amazon-web-services amazon-ec2 aws-sdk


    【解决方案1】:

    这并不是真正的 AWS/EC2 相关问题。您如何打包/运行您的应用程序?您的 jar/war 可能缺少这些类。它在本地工作,因为您的 IDE 将库添加到类路径... 您可以在此处阅读有关如何正确打包应用程序的信息: https://docs.aws.amazon.com/lambda/latest/dg/java-create-jar-pkg-maven-no-ide.html

    【讨论】:

      猜你喜欢
      • 2018-01-27
      • 1970-01-01
      • 2015-04-17
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 2019-04-20
      • 2013-04-21
      • 2013-04-14
      相关资源
      最近更新 更多