Skip to content

java.lang.ClassNotFoundException: com.sendgrid.helpers.mail.objects.Email #652

Description

@belezi

Issue Summary

On run time I always get classNotFoundException basically on every class from com.sendgrid package. Has anyone else run into this that could shed some light as to why this is happening? I am on the latest version 4.6.7

Any help is appreciated. TY

Code Snippet

import com...Notification;
import com...NotificationSendException;
import com...EmailNotificationClientInterface;
import com...NotificationResponse;
import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;
import com.sendgrid.helpers.mail.Mail;
import com.sendgrid.helpers.mail.objects.Content;
import com.sendgrid.helpers.mail.objects.Email;

import java.io.IOException;

public class SendGridEmailNotificationService implements EmailNotificationClientInterface {

	@Override
	public NotificationResponse sendEmailNotification(Notification notification) throws NotificationSendException, IOException {
		Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
		Email from = new Email("test@example.com");
		String subject = "Sending with SendGrid is Fun";
		Email to = new Email("belezi@intelycare.com");
		Mail mail = new Mail(from, subject, to, content);
		SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
		Request request = new Request();

		Response response = new Response();

		try {
			request.setMethod(Method.POST);
			request.setEndpoint("mail/send");
			request.setBody(mail.build());
			response = sg.api(request);
			if (response.getStatusCode() == 200) {

			}
			System.out.println(response.getStatusCode());
			System.out.println(response.getBody());
			System.out.println(response.getHeaders());
		} catch (IOException ex) {
			throw ex;
		}
		return this.processResponse(notification, response);
	}

	private NotificationResponse processResponse(Notification notification, Response response){
		NotificationResponse notificationResponse = new NotificationResponse();
		notificationResponse.setErred(notification.getErredNotification());
		notificationResponse.setSent(!notification.getErredNotification());
		return notificationResponse;
	}
}

pom.xml file

Code Snippet

<dependency>
			<groupId>com.sendgrid</groupId>
			<artifactId>java-http-client</artifactId>
			<version>4.3.6</version>
		</dependency>
		<dependency>
			<groupId>com.sendgrid</groupId>
			<artifactId>sendgrid-java</artifactId>
			<version>4.6.7</version>
		</dependency>

Exception/Log

ERROR [2020-10-20 20:35:24,287] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: 98ade0ddcde6ee9c
! java.lang.ClassNotFoundException: com.sendgrid.helpers.mail.objects.Content
! at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
! at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
! at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
! ... 64 common frames omitted
! Causing: java.lang.NoClassDefFoundError: com/sendgrid/helpers/mail/objects/Content

Technical details:

  • sendgrid-java version: 4.6.7
  • java version:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions