Tomcat 5.5.20 and JavaMail Sessions

Posted by Lucio Benfante Tue, 13 Mar 2007 06:40:00 GMT

You’ll find an article in italian on the same topic in my personal blog.

In Tomcat you can define a JNDI Resource for a JavaMail session putting the following code in you Context definition:

<Resource name="mail/Session" auth="Container"
            type="javax.mail.Session"
            mail.smtp.host="localhost"/>

And in you web.xml:

<resource-ref>
  <res-ref-name>mail/Session</res-ref-name>
  <res-type>javax.mail.Session</res-type>
  <res-auth>Container</res-auth>
</resource-ref>

Then you can use it in you code:

Context initCtx = new InitialContext();
Session session =
    (Session) envCtx.lookup("java:comp/env/mail/Session");

Using Tomcat 5.5.20 (and 5.5.17, and 5.5.23…and maybe other versions) the last statement will produce a ClassNotFoundException: org.apache.naming.factory.MailSessionFactory. The cause is obviously that class is missing from the common/lib/naming-factory.jar distributed by Tomcat. I don’t know if it was a (repeated) problem in building Tomcat. Luckly the source code of that class is still present in the source distribution of Tomcat. Simply it isn’t included in the build process if you don’t have the JavaMail and the JavaBeans Activation Framework in the build classpath. So I re-built the naming-factory.jar file and substituted in common/lib.

You can rebuild your own JAR, or download my new naming-factory.jar.

I discovered this problem (bug?) installing LifeRay 4.1.2 using the WAR distribution. On the contrary the LifeRay-Tomcat bundle contains the correct naming-factory.jar yet. The LifeRay error in this case is more obscure. It reports a javax.naming.NameNotFoundException: Name mail is not bound in this Context! Of course the JNDI Resource is correctly configured. This happens because LifeRay try to guess the JNDI name of the resource, that changes for the different application servers. So that exception comes from one of the attempts, and the real problem is lost and hidden. So, if you’ll see a such message, don’t spend time re-re-re-configuring your JNDI resources…but patch Tomcat!

Posted in ,  | Tags , , ,  | 39 comments | no trackbacks

Comments

  1. Avatar Solmaz said 35 days later:

    I used your jar and my problem solved. thank you.

  2. Avatar Lucio Benfante said 40 days later:

    Hi Solmaz. You’re welcome.

  3. Avatar Ven said 70 days later:

    I am using Liferay 4.1.2 but with JBOSS/Tomcat. Can I use this jar.

    Thanks

  4. Avatar Thanks said 73 days later:

    I downloaded your jar and it worked

  5. Avatar prasanna said 322 days later:

    Thanks for the valuable details provided

  6. Avatar Salil said 853 days later:

    Great effort. Thanks For Demo

  7. Avatar Leonardo said 1087 days later:

    Thank you. I use your solution and it resolve. so i now can use tomcat 5.5 for my debug and not only tomcat 6 thank you very mutch

  8. Avatar how to save your marriage said 1533 days later:

    The supreme happiness of life is the conviction that we are loved .

  9. Avatar ways to get your ex back said 1533 days later:

    Great literature is simply language charged with meaning to the utmost possible degree

  10. Avatar ways to get your ex back said 1533 days later:

    Great literature is simply language charged with meaning to the utmost possible degree

  11. Avatar Ture Religion Outlet said 1541 days later:

    Once you want to do it better, you can set your effort to it , and do not think more about the fail. Be confidence to yourself.

  12. Avatar Tiffany & CO Outlet said 1541 days later:

    Incase that Thinker thinks about passionately good enough, that Prover might turn out to be thinking as a result effectively you’ll hardly ever discussion a man or woman using a great understanding, possibly even if a product simply because significant given that the opinion that there are an important gaseous vertebrate in astronomical heft (“GOD”) which will dedicate every anniversary torturing individuals that you should not have confidence on his particular faith.

  13. Avatar Cheap Nike Air Max said 1549 days later:

    All around everyday living is definitely success. Luckily for us study will not be to get to unravel essential disputes. Everyday living on its own continue to remains to be an effective physical therapist. Your dog having your the key reason why to stay at might endure any kind of the best way. This can be the examine to seek out if a person’s mandate we know of is completed: when you are lively, doable. I actually develop in the am split amongst your aspire to help community including a aspire to have fun with the community. The following should make it very difficult so that you can system built. We do never feel dissapointed about a person moment in time with living.

  14. Avatar Ed Hardy 2011 said 1549 days later:

    Concerning a super easy doctrine: Pack what on earth is clean. Clean what on earth is 100 %. Scrape when them itches. Everyone loves everyday living for the reason that just what exactly extra could there be. I actually continue to obtain day after day very shorter for your opinions I want to assume, many of the strolling I want to bring, many of the courses I want to learn, plus many of the associates I want to find.

  15. Avatar cheap true religion jeans said 1549 days later:

    The post is written in very a good manner and it entails much useful information for me. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post.

  16. Avatar nike air force ones shoes said 1555 days later:

    Freethinkers tend to be those people who are prepared to make use of their own thoughts without having bias as well as without having fearing to comprehend stuff that conflict using their personal traditions, rights, or even values. This particular frame of mind isn’t typical, however it is crucial with regard to correct considering; exactly where it’s lacking, dialogue is actually likely to turn out to be even worse compared to ineffective.

  17. Avatar Austin Door Company said 1557 days later:

    So that exception comes from one of the attempts, and the real problem is lost and hidden. So, if you’ll see a such message, don’t spend time re-re-re-configuring your JNDI resources…but patch Tomcat!

  18. Avatar Kobe VI said 1561 days later:

    Can it be honest being suspect of your complete career as a result of handful of negative oatmeal? You can find no less than a couple of crucial distinctions, this indicates if you ask me. Initial, no-one questions in which research is proven to work, whichever wrongly recognized and also deceitful state may well every so often become supplied. Yet whether or not you can find virtually any “miraculous” treatments coming from faith-healing, over and above your bodys very own power to treatment alone, is quite significantly with problem. Second of all, the particular expose’ regarding fraudulence and also problem inside research is manufactured practically specifically simply by research. Nevertheless the coverage regarding fraudulence and also problem inside faith-healing is practically by no means completed simply by some other faith-healers.

  19. Avatar Tiffany Sale said 1567 days later:

    You detect simply because check all over that one-time part of growth for gentle perception, just about every single enchancment on the unlawful regularions, just about every single tip regarding all the diminution about fights, just about every single tip regarding more suitable treatment plan for the colorful events, or possibly just about every single minimization about captivity, just about every single ethical growth which usually there has been anywhere, is actually always contrary through put-together church buildings for the country. Document tell you really quite on purpose of the fact that Stacee religion, like put-together for the country’s church buildings, is actually nonetheless certainly is the necessary enemy about ethical growth anywhere.

  20. Avatar New Jordans 2011 said 1570 days later:

    And if the Thinker thinks passionately enough, the Prover will prove the thought so conclusively that you will never talk a person out of such a belief, even if it is something as remarkable as the notion that there is a gaseous vertebrate of astronomical heft (“GOD”) who will spend all eternity torturing people who do not believe in his religion.

  21. Avatar Nike Air Force Ones Shoes said 1575 days later:

    For a long time, an important poisonous battle was waged around just a few daring people today in consideration and even legend for the person half, additionally, the very good unaware christian majority in the several other. It is the fight around Discipline and even Confidence. That small amount of contain become a huge hit to help you good reason, to help you dignity, to help you regulations, to help you versatility, with the best-known, so to bliss these nowadays. Several contain become a huge hit to help you bias, to help you fright, to help you magical, to help you captivity, with the strange, so to misery hereafter. That small amount of contain proclaimed “Think” Several contain proclaimed “Believe! inch

  22. Avatar Herve Leger Dress said 1578 days later:

    Don’t believe things. Aspect important things even on a dimensions from probabilities. The things which feel virtually all stupid, position according to ‘Low Probability’, not to mention the things which feel virtually all credible, most people position according to ‘High Probability’. Do not ever are convinced things. While you are convinced things, most people give up great deal of thought. The better important things people think, typically the reduced subconscious recreation. Any time you are convinced a specific thing, with an impression concerning all topic area, then an thought process recreation helps prevent absolutely, that may be medically taken into consideration a sign from departure, in these modern times through medical related rehearse. Which means position important things even on a dimensions and / or successful opportunity, without having to are convinced and / or disbelieve things absolutely.

  23. Avatar Cheap Nike Air Max said 1588 days later:

    If you’d like to factor related to beliefs, and gives a good reasoned (and reason-responsive) shield for beliefs as being an supplemental category of confidence worthy of exceptional interest, I will be wanting to execute. That i without doubt grants any daily life within the method for beliefs; what precisely I wish to look at may be a reasoned yard to have beliefs very seriously as a technique of buying into the actuality, not, mention, basically as a technique consumers coziness their selves together with oneself (a notable work that undertake require seriously). However , you must not hope my family that will associate with an individual’s defence for beliefs as the way to actuality whenever for all issue everyone capture the fancy of stomach muscles will better dispensation that you’re expected planning to excuse. Prior to you capture the fancy of beliefs anytime factor has got everyone respected suitable neighborhood, contemplate irrespective of whether everyone actually want to drop factor anytime factor is certainly working for you.

  24. Avatar portable generators said 1657 days later:

    Thank you for sharing. Very happy to see these and believe that your point of view.you might be interested in looking at the inverter generator, which is relatively small and become one of the most popular lines in this form of invention these days.

  25. Avatar Wholesale gadgets said 1766 days later:

    use your solution and it resolve. so i now can use tomcat 5.5 for my debug a

  26. Avatar Snapdeal Facebook Page said 1823 days later:

    i downloaded the jar file and its really worked man thanks

  27. Avatar Snapdeal Facebook Page said 1823 days later:

    i downloaded the jar file and its really worked man thanks

  28. Avatar GenevaCHAMBERS33 said 1890 days later:

    Have no enough money to buy a house? You should not worry, just because that’s possible to receive the business loans to resolve all the problems. So take a college loan to buy all you require.

  29. Avatar Mitzi35KENNEDY said 1918 days later:

    I received my first credit loans when I was 32 and this helped my business a lot. But, I need the term loan once more time.

  30. Avatar Adolfo said 2226 days later:

    Appreciate this post. Will try it out.

  31. Avatar www.blogster.com said 2226 days later:

    It’s going to be end of mine day, however before finish I am reading this wonderful paragraph to increase my knowledge.

  32. Avatar Kai said 2227 days later:

    I blog often and I truly thank you for your content. The article has really peaked my interest. I’m going to take a note of your website and keep checking for new details about once a week. I subscribed to your RSS feed too.

  33. Avatar flex belt said 2227 days later:

    Blogs and Web Credibility Numerous individuals have turned to newspaper web sites for details.

  34. Avatar Rhea said 2231 days later:

    I am regular reader, how are you everybody? This piece of writing posted at this site is in fact good.

  35. Avatar Jake said 2557 days later:

    Wow. This is really interesting. I’m impressed with the way you have explained JavaMail and the JavaBeans Activation. Where can I find the presentations of these topics? Kindly provide more information regarding that. Thanks a lot for submitting this informative post. more here

  36. Avatar geebranz said 5323 days later:

    I guess you’re right

    Holiday Season

  37. Avatar geebranz said 5323 days later:

    Spread goodvibes

    Holiday Season

  38. Avatar st george laser hair removal said 5324 days later:

    This is such a great help! I’ve been struggling for days already, soo glad i found this site! thanks for sharing!

  39. Avatar laser hair removal colorado springs said 5324 days later:

    Cant believe this article made soo much sense now. You really have a talent for this! Continue pressing on!

Trackbacks

Use the following link to trackback from your own site:
http://www.jugpadova.it/articles/trackback/21441

(leave url/email »)

   Comment Markup Help Preview comment