• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail doesn't work in Web project  RSS feed

 
Abhi jitSingh
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!