Forums Register Login

JavaMail doesn't work in Web project

+Pie Number of slices to send: Send
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?
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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.
Run away! Run away! Here, take this tiny ad with you:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1154 times.
Similar Threads
Generate Dynamic Web Project Maven
JavaMail doesn't work in Web project
how to create a file in tomcat?
Adding maven projects to Servers added to Eclipse 3.4
Dynamic Web project with multiple Java projects
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:02:05.