You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Richard Frovarp <rf...@apache.org> on 2012/11/30 20:36:51 UTC

Mail JNDI with jars in application?

I am trying to use JNDI to configure the mail session. I appear to be 
running into trouble because I don't have the mail and activation jars 
in tomcat/lib, but rather app/WEB-INF/lib.

If I put them in both places I get an error, If I just leave them in the 
application I get ClassNotFoundException.

The smart thing would be to put them in tomcat/lib, but I have other web 
applications running on the system without using JNDI, that have their 
own versions of mail and activation. My fear is if I put the file in 
tomcat/lib for this application, I'll break the other ones.

I am defining the JNDI values inside of the application's context. Is 
there any way to not put it in tomcat/lib and still have it work? Or if 
I put them in tomcat/lib, will my existing applications still work just 
fine since they aren't using JNDI?

Thanks,
Richard

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Mail JNDI with jars in application?

Posted by Daniel Mikusa <dm...@vmware.com>.
On Nov 30, 2012, at 2:36 PM, Richard Frovarp wrote:

> I am trying to use JNDI to configure the mail session. I appear to be running into trouble because I don't have the mail and activation jars in tomcat/lib, but rather app/WEB-INF/lib.
> 
> If I put them in both places I get an error, If I just leave them in the application I get ClassNotFoundException.

According to step #4, you need to put them into "$CATALINA_HOME/lib", and as you indicated if they are in both "$CATALINA_HOME/lib" and the web application's lib directory then you'll get an error.

https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JavaMail_Sessions

> 
> The smart thing would be to put them in tomcat/lib, but I have other web applications running on the system without using JNDI, that have their own versions of mail and activation. My fear is if I put the file in tomcat/lib for this application, I'll break the other ones.

If you don't remove it from the web applications lib directories then it will break.  Based on what you reported above and by what is documented, if you add them to "$CATALINA_HOME/lib" and a web application ships with them then you'll get an error.

You would want to add it to "$CATALINA_HOME/lib" and remove it from your applications.  If you do that, it should work so long as your applications are compatible with the version you put in "$CATALINA_HOME/lib".

Dan


> 
> I am defining the JNDI values inside of the application's context. Is there any way to not put it in tomcat/lib and still have it work? Or if I put them in tomcat/lib, will my existing applications still work just fine since they aren't using JNDI?
> 
> Thanks,
> Richard
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Mail JNDI with jars in application?

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Richard,

On 11/30/12 2:36 PM, Richard Frovarp wrote:
> I am trying to use JNDI to configure the mail session. I appear to
> be running into trouble because I don't have the mail and
> activation jars in tomcat/lib, but rather app/WEB-INF/lib.
> 
> If I put them in both places I get an error, If I just leave them
> in the application I get ClassNotFoundException.
> 
> The smart thing would be to put them in tomcat/lib, but I have
> other web applications running on the system without using JNDI,
> that have their own versions of mail and activation. My fear is if
> I put the file in tomcat/lib for this application, I'll break the
> other ones.
> 
> I am defining the JNDI values inside of the application's context.
> Is there any way to not put it in tomcat/lib and still have it
> work? Or if I put them in tomcat/lib, will my existing applications
> still work just fine since they aren't using JNDI?

Tomcat uses the server's 'common' ClassLoader as the context for
loading JNDI resources while initializing a Context (webapp).
Unfortunately, if you want Tomcat to manage a JNDI resource for you,
all dependencies for that resource must be in CATALINA_BASE/lib.

It's not really possible to bootstrap a webapp using its own
WebappClassLoader (which loads from WEB-INF/lib then delegates to the
parent) because the context can specify its own classloader as part of
its configuration. Re-threading the class loader during context
initialization would be ... tricky.

IIRC, JavaMail itself is quite backward-compatible. Just throw the
latest version into CATALINA_BASE/lib and remove the others from the
individual webapps.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlC5K44ACgkQ9CaO5/Lv0PDzQACeLPc9JupHx52+mBJ9eVV5XGJy
1wcAnjUhi1yIH0MNcDX+jTfn3ApbgGNP
=2f1X
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org