• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaMail doesn't work in Web project

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If I create a simple Java Project (new -> Java Project) and try sending an email using JAVAMAIL (mail.jar and activation.jar) through a class with a main(), it works fine - EXPECTED.

But If I create a WEB Project and do the same (with same code and jars), I get
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/mail/util/LineInputStream
at javax.mail.Session.loadProvidersFromStream(Session.java:928) - NOT EXPECTED

However, If I deploy the WEB project on a server and run, the same setup works fine again - EXPECTED.

Please tell me why the NOT EXPECTED case happens?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you putting the required JAR files?

If you are creating a WAR file for your web application, then the JAR files that are necessary for JavaMail should go into WEB-INF/lib inside your WAR file.
 
Abhi jitSingh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper, yes the jars are in web-inf/lib folder. It is not the issue with the deployment or running it as a WAR. Deploying and executing the whole is never an issue. Allow me to emphasize that it could be an issue with Myeclispe. If Myeclipse knows how to find jars/classes when it a simple Java project then why is it not able to do the same with the same set of jars and classes in case of a WEB Project. You may experiment. You just need mail.jar and activation.jar and a simple mail sending java code(in class with a main function). Do the same with a WEB Project and a simple Plain Java project.
 
Abhi jitSingh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In fact, To get it running (when it failed in WEB Project ) I even added jars to classpath, added them through a user library besides having them in webContent/web-inf/lib folder.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic