Results 1 to 9 of 9

Thread: problem using Javamail

  1. #1
    Join Date
    Oct 2009
    Posts
    4

    Default problem using Javamail

    Hi all,

    I am trying to send e-mail using org.springframework.mail.javamail.JavaMailSenderIm pl but I get this exception when starting my Tomcat server.

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSender' defined in file [E:\...\WEB-INF\classes\config\spring\applicationContext-action.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/AuthenticationFailedException
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:883)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:839)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:440)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
    	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
    	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)
    	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
    	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:255)
    	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:199)
    	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:45)
    	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3843)
    	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4342)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
    	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    	at org.apache.catalina.core.StandardService.start(StandardService.java:516)
    	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    	at org.apache.catalina.startup.Catalina.start(Catalina.java:578)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    	at java.lang.reflect.Method.invoke(Method.java:597)
    	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
    	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
    Caused by: java.lang.NoClassDefFoundError: javax/mail/AuthenticationFailedException
    	at java.lang.Class.getDeclaredConstructors0(Native Method)
    	at java.lang.Class.privateGetDeclaredConstructors(Class.java:2389)
    	at java.lang.Class.getConstructor0(Class.java:2699)
    	at java.lang.Class.getDeclaredConstructor(Class.java:1985)
    	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:54)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:877)
    	... 31 more
    Caused by: java.lang.ClassNotFoundException: javax.mail.AuthenticationFailedException
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    	at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    	... 37 more
    This is my bean declaration:

    Code:
    	<bean id="mailSender"
    		class="org.springframework.mail.javamail.JavaMailSenderImpl">
    		<property name="host" value="mail.xserver.com" />
    	</bean>
    I have the mail-1.4.1.jar added in my build path, so I don't understand why it generates a java.lang.NoClassDefFoundError.

    Any help would be greatly appreciated!
    Last edited by mojitoking; Oct 12th, 2009 at 07:10 AM.

  2. #2
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    Do you have the activation.jar in your classpath?

  3. #3
    Join Date
    Oct 2009
    Posts
    4

    Default

    Hi Chudak,

    Yes, I have activation-1.1.jar in my build path, what else could be wrong?

  4. #4
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    You say it's in your BUILD path...where are the jars in tomcat? How are you launching tomcat? How are you deploying your application?

  5. #5
    Join Date
    Oct 2009
    Posts
    4

    Default

    I use Eclipse IDE to launch tomcat v6.0.18 and the jars along with the app are put into the server every time i create a build with Eclipse

  6. #6
    Join Date
    Jan 2008
    Location
    San Diego
    Posts
    780

    Default

    This is like pulling teeth...

    How are you packaging your application? Are you deploying it exploded or as an archive file (WAR)? Where are the jars on tomcat? In the application package? In the TOMCAT_HOME/lib directory?

    Have you cleaned out the working directory between application runs?

  7. #7
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    I use Eclipse IDE to launch tomcat v6.0.18 and the jars along with the app are put into the server every time i create a build with Eclipse
    Well actually that is not entirely true. It only exports those jars you told eclipse to export, they should be part of your EE Library and should be exported, else they are NOT on your runtime classpath.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  8. #8
    Join Date
    Oct 2009
    Posts
    4

    Default

    Thanks Marten, I overlooked that detail and once I checked the mail and activation libraries in my EE module dependecies the exception was no longer generated! That led me to a few other mistakes I had made. Thank you very much for your insight!

  9. #9
    Join Date
    Jan 2009
    Location
    Pune
    Posts
    58

    Default

    1. You are using Eclipse
    2. You already add libraries in buildpath

    Then try this..
    copy all libraries in lib folder of your Eclipse project (if it is dynamic web project) and then run your project again

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •