ClassNotFoundException - EC2 ubuntu实例上的AmazonSimpleEmailServiceClientBuilder

时间:2018-03-17 15:48:17

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

我想在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>

我得到的错误信息是:

  

线程“main”中的异常java.lang.NoClassDefFoundError:   COM / amazonaws /服务/ simpleemail / AmazonSimpleEmailServiceClientBuilder

     

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

当我在本地启动我的应用程序时,只会出现一个例外,即找不到任何区域但找不到该类没有问题。

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

1 个答案:

答案 0 :(得分:0)

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