简体   繁体   中英

java.lang.NoClassDefFoundError: javax/mail/MessagingException unsolved

I'm trying to add the javax.mail jar to my classpath but I get 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've readed in other post that it could be fixed adding the dependecy to the pom.xml, so I did it:

pom.xml

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

项目

But still I'm getting the error ..can someone help me with this?

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

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

the javax/mail/MessagingException already exists in version 1.4. So I guess this is just an assembly issue within the IDE. Refreshing the pom dependencies and checking the artifact the IDE builds up should be sufficient.

You should add the jar to the server Tomcat.

  1. Open launch configuration

    您应该打开启动配置

  2. Add external jar (look for your email jar)

    添加外部 jar 并查找您的电子邮件 jar

The most recent version of the Java Mail API is

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

Do you get the same error with this version?

This class has been present in all versions of Javamail I have ever used. Clearly you don't have the Javamail JAR(s) on your CLASSPATH, as for any other ClassNotFoundException.

You mixed the classpath by using maven and manually added references in eclipse.

Disable the "maven nature" make a mvn eclipse:clean on commandline refresh your project and convert it to maven project and then try again.

To clearify: Where have you added the mail api in pom? under <dependecies> or under <dependecyManagement ?

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

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

  1. If that doesn't work, manually place the jar file in your .m2\\repository\\javax\\<folder>\\<version>\\ directory.

You will use maven-dependency-plugin to copy project dependencies to somewhere else.

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>

Following manifest file will be generated. The 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

This worked for me. Source: MKyong.com

I had similar problem with javax.mail.Activator class. Solution was delete from war javax.mail and javax.activation and add it on {tomcat}\\lib folder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM