12

I am using eclipse indigo to run my tomcat server, when I am launching tomcat server, the tomcat server successfully up and running, but with error shown in the console.

ERROR  - ContextLoader[177]: Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'com.huahsin68.MyBoc' defined in class path resource [my-spring.xml]: Class that bean class [com.huahsin68.MyBocImp] depends on not found; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
java.lang.NoClassDefFoundError: javax/mail/MessagingException

It seems like the MessagingException wasn't found. I have check in the Java Build Path > Libraries, I notice that javax.mail_1.4.0.v200105080615.jar was there. This jar file is locate under eclipse > plugins folder. Is there anything solution to rectify this problem?

THanks @!

huahsin68
  • 6,819
  • 20
  • 79
  • 113

5 Answers5

20

With Maven, you can add the following dependency:

<dependency>
  <groupId>javax.mail</groupId>
  <artifactId>mail</artifactId>
  <version>1.4.5</version>
</dependency>
Benny Code
  • 51,456
  • 28
  • 233
  • 198
  • 1
    Current version is 1.5.6. Also groupId and artifactId changed (see this question: http://stackoverflow.com/questions/22020533/javamail-api-from-maven. Now you should use "com.sun.mail javax.mail 1.5.6" . You can also check it here: https://maven.java.net/#nexus-search;gav~com.sun.mail~javax.mail~~~~kw,versionexpand. – Line May 12 '17 at 08:33
11

Try the following:

  1. Download the java mail jars from: http://www.oracle.com/technetwork/java/javamail/index-138643.html
  2. Add the jars to your WEB-INF/lib folder
  3. Add the jars to Java Build Path > Libraries

That should do it.

Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
  • I have did a search in Maven directory and found out there is a mail.jar. It seems like the eclipse not able to resolve the link. – huahsin68 Jul 19 '11 at 08:24
7

For gradle/android users, in build.gradle (Module app):

compile 'javax.mail:mail:1.4.1' 
Tim
  • 41,901
  • 18
  • 127
  • 145
2

I had a similar problem, running tomcat stand-alone (that is, not through Eclipse). I copied mail-1.4.jar to my tomcat/lib directory. This worked for me.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
0

For those conning late in this .. I got the same error resolved by adding below jar. geronimo-javamail_1.4_mail-1.8.3.jar

AmitG
  • 519
  • 6
  • 19