Java.lang.NoClassDefFoundError: javax / mail / MessagingException not resolved

I'm trying to add javax.mail jar to my classpath, but getting this error:

java.lang.NoClassDefFoundError: javax/mail/MessagingException at java.lang.Class.getDeclaredConstructors0(Native Method) at java.lang.Class.privateGetDeclaredConstructors(Class.java:2663) at java.lang.Class.getDeclaredConstructors(Class.java:2012) at org.springframework.beans.factory.annotation. 

I read in another post that it would be possible to fix the addition of dependecy in pom.xml, so I did this:

pom.xml

 <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.3</version> </dependency> 

project

But still I get an error message .. can someone help me?

+7
source share
8 answers

Also with version 1.4.3 there is no longer an artifact identifier called mail. If you want to use 1.4.3 you must use this dependency

 <dependency> <groupId>javax.mail</groupId> <artifactId>mailapi</artifactId> <version>1.4.3</version> </dependency> 
+8
source

javax/mail/MessagingException already exists in version 1.4. So I assume this is just a build problem in the IDE. Mastering the pom dependencies and checking the artifact generated by the IDE should be sufficient.

+1
source

You must add the jar to the Tomcat server.

  1. Open launch configuration

    You should open launch configuration

  2. Add external jar (look for the jar with email)

    Add external jar and look for your email jar

+1
source

The latest version of the Java Mail API is

 <dependency> <groupId>javax.mail</groupId> <artifactId>javax.mail-api</artifactId> <version>1.5.2</version> </dependency> 

Are you getting the same error with this version?

0
source

This class is present in all versions of Javamail that I have ever used. Obviously, you do not have Javamail JAR files on your CLASSPATH, as with any other ClassNotFoundException.

0
source

You mixed the classpath with maven and manually added the links in eclipse.

Disable "maven nature" so that the mvn eclipse:clean command on the command line updates your project and convert it to maven project , and then try again.

To clear: where did you add api mail to pom? under <dependecies> or under <dependecyManagement ?

0
source

Even I came across a similar error. Try below 2 steps (the first of which has already been recommended here) - 1. Add a dependency to your pom.xml

  <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4.3</version> </dependency> 
  1. If this does not work, manually place the jar file in the .m2\repository\javax\<folder>\<version>\ directory.
0
source

You will use the maven-dependency-plugin to copy project dependencies to another location.

Add this to pom.xml

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.4</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>com.mkyong.core.App</mainClass> <classpathPrefix>dependency-jars/</classpathPrefix> </manifest> </archive> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.5.1</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory> ${project.build.directory}/dependency-jars/ </outputDirectory> </configuration> </execution> </executions> </plugin> 

The following manifest file will be created. Project dependencies will be copied to {project} / target / dependency-jars /.

 manifest-Version: 1.0 Built-By: mkyong Build-Jdk: 1.6.0_35 Class-Path: dependency-jars/log4j-1.2.17.jar Created-By: Apache Maven Main-Class: com.mkyong.core.App Archiver-Version: Plexus Archiver 

It worked for me. Source: MKyong.com

0
source

Source: https://habr.com/ru/post/981889/


All Articles