-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
java.lang.ClassNotFoundException: com.sendgrid.helpers.mail.objects.Email #652
Comments
Thank you for reporting this @belezi! I was able to recreate in the following manner: mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false Added the dependencies to <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> Added the following code to package com.mycompany.app;
import com.sendgrid.SendGrid;
import com.sendgrid.helpers.mail.Mail;
import com.sendgrid.helpers.mail.objects.Email;
import com.sendgrid.helpers.mail.objects.Content;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.Method;
import java.io.IOException;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws IOException {
Email from = new Email("[email protected]");
String subject = "Sending with Twilio SendGrid is Fun";
Email to = new Email("[email protected]");
Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
Mail mail = new Mail(from, subject, to, content);
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
try {
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
} cd my-app
mvn package
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog. |
I am having the exact same issue. This needs to be resolved ASAP in order to comply with SendGrid migrating away from username/password to API Keys. |
NOTE: I was able to get this to work by updating the <build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.sgtest.SendGridTest2.App</mainClass>
</transformer>
</transformers>
<!-- exclude signed Manifests -->
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.sgtest.SendGridTest2.App</mainClass>
</manifest>
<manifestEntries>
<Class-Path>./public/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build> |
I am having the exact same issue but I am not using maven, I was just downloading the JAR file and on run time I always get classNotFoundException basically on every class from com.sendgrid package. Is there any solution for me? |
I was able to get this example to work without maven by including two libraries: sendgrid-java-4.6.7.jar and java-http-client-latest.jar. I believe I downloaded the sendgrid-java-4.6.7.jar from the Maven repository. A link to java-http-client-latest.jar can be found at https://github.com/sendgrid/sendgrid-java. I believe you also need to include three jackson libraries: jackson-annotation-2.9.0.jar, jackson-core-2.9.2.jar and jackson-databind-2.9.2.jar. I hope this helps. |
Thanks, I have download sendgrid-java-4.6.7.jar and all the dependencies JAR base on the docs at maven repository at the https://mvnrepository.com/artifact/com.sendgrid/sendgrid-java/4.6.7 but still getting the same runtime classNotFoundException for any class from com.sendgrid. any other idea? |
I did not use the java-http-client library from the maven repository. As I stated above, I went to https://github.com/sendgrid/sendgrid-java and followed the java-http-client link on that page. It led me to the jar named java-http-client-latest.jar. Try that. |
thanks again, I have tried but still i am keeping getting the Class Not Found Exception. |
I don't know what else to tell you. I am using java 1.8, specifically jre.1.8.0_271. Don't know if that could impact your build. |
Any solution for this? Exception in thread "main" java.lang.NoClassDefFoundError: com/sendgrid/Email |
I had the same issue. For me, the problem was that maven was pulling older version of sendgrid-java even though 4.7.2 was the transitive dependency. So the fix was to add the dependency 4.7.2 directly in pom.xml and not depend on transitive dependency. |
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
pom.xml file
Code Snippet
Exception/Log
Technical details:
The text was updated successfully, but these errors were encountered: