You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kevin SeongHyun Lee <pu...@gmail.com> on 2008/10/24 14:31:41 UTC

How can I use a class in javax package from the jar file in WEB-INF/lib instead of the one in common/lib.

Hello,

I'm trying to use JavaMail and the necessary libraries are in the 
WEB-INF/lib of my application. It works fine in my development 
environment. However, the problem is that after it is installed in the 
production environment and tries to send an email, it always throws 
NoSuchProviderException exception like the following lines.

javax.mail.NoSuchProviderException: smtp
    at javax.mail.Session.getService(Session.java:794)
    at javax.mail.Session.getTransport(Session.java:718)
    at javax.mail.Session.getTransport(Session.java:661)
    at javax.mail.Session.getTransport(Session.java:641)
    at javax.mail.Session.getTransport(Session.java:696)
    at javax.mail.Transport.send0(Transport.java:186)
    at javax.mail.Transport.send(Transport.java:118)
    ...

I found that the common/lib directory has javamail.jar file which is a 
different version of JavaMail belongs to Tomcat in the production 
environment and it causes the problem.  If I remove one of them, it 
works yet I have to keep the libraries in my application as required by 
my client, it must be designed to work in any Tomcat server with default 
Tomcat libraries and the server admin also said he has to keep it there.

So I would like to know if there is any way to choose which libraries to 
use.  As it is in javax package, common/lib has higher priority I think. 
Is there any way to change it so that my application uses JavaMail in 
WEB-INF/lib instead of common/lib one?

Regards,
Kevin

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


Re: How can I use a class in javax package from the jar file in WEB-INF/libinstead of the one in common/lib.

Posted by Kevin SeongHyun Lee <pu...@gmail.com>.
Yeah, absolutely. :)

Well, they have their policy though. So I have to respect that.

Thanks Chuck.

Regards,
Kevin


2008/10/25 Caldarale, Charles R <Ch...@unisys.com>

> > From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> > Subject: Re: How can I use a class in javax package from the
> > jar file in WEB-INF/libinstead of the one in common/lib.
> >
> > Well, that javamail.jar in the common/lib is, as far as I
> > know, from the repository of the Linux server.
>
> Hence my comment about the "3rd-party repackager" - which frequently create
> problems that installations of a real Tomcat do not have.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: How can I use a class in javax package from the jar file in WEB-INF/libinstead of the one in common/lib.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> Subject: Re: How can I use a class in javax package from the
> jar file in WEB-INF/libinstead of the one in common/lib.
>
> Well, that javamail.jar in the common/lib is, as far as I
> know, from the repository of the Linux server.

Hence my comment about the "3rd-party repackager" - which frequently create problems that installations of a real Tomcat do not have.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: How can I use a class in javax package from the jar file in WEB-INF/libinstead of the one in common/lib.

Posted by Kevin SeongHyun Lee <pu...@gmail.com>.
Thanks Chuck for your reply.

Well, that javamail.jar in the common/lib is, as far as I know, from the
repository of the Linux server.

Yeah, I think so too. I may need to provide to or I can simply document it
so the client can know what to do.

Regards,
Kevin


2008/10/25 Caldarale, Charles R <Ch...@unisys.com>

> > From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> > Subject: How can I use a class in javax package from the jar
> > file in WEB-INF/libinstead of the one in common/lib.
> >
> > it must be designed to work in any Tomcat server
> > with default Tomcat libraries and the server admin
> > also said he has to keep it there.
>
> The javamail.jar file is *not* part of the default Tomcat libraries - your
> sysadmin (or some 3rd-party Tomcat repackager) put it there, thereby
> imposing it on all the webapps for that Tomcat installation.
>
> You may have to provide two versions of your webapp - one with javamail.jar
> included, one without, and let the customer choose which to use based on the
> environment.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: How can I use a class in javax package from the jar file in WEB-INF/libinstead of the one in common/lib.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> Subject: How can I use a class in javax package from the jar
> file in WEB-INF/libinstead of the one in common/lib.
>
> it must be designed to work in any Tomcat server
> with default Tomcat libraries and the server admin
> also said he has to keep it there.

The javamail.jar file is *not* part of the default Tomcat libraries - your sysadmin (or some 3rd-party Tomcat repackager) put it there, thereby imposing it on all the webapps for that Tomcat installation.

You may have to provide two versions of your webapp - one with javamail.jar included, one without, and let the customer choose which to use based on the environment.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: How can I use a class in javax package from the jar file in WEB-INF/lib instead of the one in common/lib.

Posted by Kevin SeongHyun Lee <pu...@gmail.com>.
Oh, that makes perfect sense. Thanks Chuck.

Regards,
Kevin



2008/10/25 Caldarale, Charles R <Ch...@unisys.com>

> > From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> > Subject: Re: How can I use a class in javax package from the
> > jar file in WEB-INF/lib instead of the one in common/lib.
> >
> > Even if it is loaded first, I believe, it should work
> > as both libraries are the same javamail
>
> What frequently happens is that some classes get loaded from both jars, but
> since they're under different classloaders, the JVM treats them as different
> classes.  When code in one class tries to utilize instances created from the
> other classloader, it can't, since the "instance of" operation fails.
>
> > Does anyone know how to solve this without removing any files?
>
> I don't.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: How can I use a class in javax package from the jar file in WEB-INF/lib instead of the one in common/lib.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> Subject: Re: How can I use a class in javax package from the
> jar file in WEB-INF/lib instead of the one in common/lib.
>
> Even if it is loaded first, I believe, it should work
> as both libraries are the same javamail

What frequently happens is that some classes get loaded from both jars, but since they're under different classloaders, the JVM treats them as different classes.  When code in one class tries to utilize instances created from the other classloader, it can't, since the "instance of" operation fails.

> Does anyone know how to solve this without removing any files?

I don't.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: How can I use a class in javax package from the jar file in WEB-INF/lib instead of the one in common/lib.

Posted by Kevin SeongHyun Lee <pu...@gmail.com>.
Hey, Chuck.

Thanks :D

I read that tomcat doc as well yet missed that. I probably didn't really pay
attention. :( Thank you. :)

Yeah, I think you're right. After I said common/lib one is loaded first, I
found something weird. Even if it is loaded first, I believe, it should work
as both libraries are the same javamail (but different versions).

There is probably some kind of conflict with both jar files so it is not
working, isn't it?

I'm not sure why it is happening yet I think this is what I'm faced with.
http://confluence.atlassian.com/display/CONF27/Frequently+Asked+Questions#FrequentlyAskedQuestions-3.2

Does anyone know how to solve this without removing any files?

Regards,
Kevin




2008/10/25 Caldarale, Charles R <Ch...@unisys.com>

> > From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> > Subject: Re: How can I use a class in javax package from the
> > jar file in WEB-INF/lib instead of the one in common/lib.
> >
> > I believe, if a class is in java or javax package it might not
> > be loaded from the libraries in the WEB-INF/lib directory first
> > but the common/lib one
>
> Not true; WEB-INF/lib is searched before common/lib.  However, if a class
> has already been loaded via the common/lib classloader, it may prevent use
> of the one in the webapp's jars.
>
> > as mentioned in the FAQ
> > found from the following link.
> > http://ws.apache.org/axis/faq.html#faq5
> >
> > "*Why do some classes fail to load under Tomcat?*
> >
> > Tomcat will not load classes with package names starting
> > "java." or "javax."
> > from the WEB-INF directory. jars containing such classes need to be
> > installed in $TOMCAT_HOME/common/lib rather than in
> > WEB-INF/lib. Currently
> > (April 25, 2002) jaxrpc.jar is such a jar."
>
> Note the date - 6.5 years old, and no longer accurate (possibly not ever
> accurate), at least not as written.  Tomcat will happily load java.* or
> javax.* classes from WEB-INF/lib, but will ignore any jars containing either
> of these classes:
>  javax.servlet.Servlet
>  javax.servlet.jsp.JspPage
>
> Here's the real info on Tomcat 5.5 classloading:
> http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you received
> this in error, please contact the sender and delete the e-mail and its
> attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: How can I use a class in javax package from the jar file in WEB-INF/lib instead of the one in common/lib.

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Kevin SeongHyun Lee [mailto:public.class.kevin@gmail.com]
> Subject: Re: How can I use a class in javax package from the
> jar file in WEB-INF/lib instead of the one in common/lib.
>
> I believe, if a class is in java or javax package it might not
> be loaded from the libraries in the WEB-INF/lib directory first
> but the common/lib one

Not true; WEB-INF/lib is searched before common/lib.  However, if a class has already been loaded via the common/lib classloader, it may prevent use of the one in the webapp's jars.

> as mentioned in the FAQ
> found from the following link.
> http://ws.apache.org/axis/faq.html#faq5
>
> "*Why do some classes fail to load under Tomcat?*
>
> Tomcat will not load classes with package names starting
> "java." or "javax."
> from the WEB-INF directory. jars containing such classes need to be
> installed in $TOMCAT_HOME/common/lib rather than in
> WEB-INF/lib. Currently
> (April 25, 2002) jaxrpc.jar is such a jar."

Note the date - 6.5 years old, and no longer accurate (possibly not ever accurate), at least not as written.  Tomcat will happily load java.* or javax.* classes from WEB-INF/lib, but will ignore any jars containing either of these classes:
  javax.servlet.Servlet
  javax.servlet.jsp.JspPage

Here's the real info on Tomcat 5.5 classloading:
http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

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


Re: How can I use a class in javax package from the jar file in WEB-INF/lib instead of the one in common/lib.

Posted by Kevin SeongHyun Lee <pu...@gmail.com>.
Thank you P for your reply.

Well, it sounds weird, doesn't it? :D

It's indeed not a company but a university so the application is running on
the server at the uni. However, the application development is funded by
some other organisation. :)

We are now offering the service of the application yet there will be
possibly some opportunity that this application will run on another server.

Generally what you said is correct. However, I believe, if a class is in
java or javax package it might not be loaded from the libraries in the
WEB-INF/lib directory first but the common/lib one, as mentioned in the FAQ
found from the following link.
http://ws.apache.org/axis/faq.html#faq5

"*Why do some classes fail to load under Tomcat?*

Tomcat will not load classes with package names starting "java." or "javax."
from the WEB-INF directory. jars containing such classes need to be
installed in $TOMCAT_HOME/common/lib rather than in WEB-INF/lib. Currently
(April 25, 2002) jaxrpc.jar is such a jar."


Regards,
Kevin




2008/10/25 Pid <p...@pidster.com>

> Kevin SeongHyun Lee wrote:
> > Hello,
> >
> > I'm trying to use JavaMail and the necessary libraries are in the
> > WEB-INF/lib of my application. It works fine in my development
> > environment. However, the problem is that after it is installed in the
> > production environment and tries to send an email, it always throws
> > NoSuchProviderException exception like the following lines.
> >
> > javax.mail.NoSuchProviderException: smtp
> >    at javax.mail.Session.getService(Session.java:794)
> >    at javax.mail.Session.getTransport(Session.java:718)
> >    at javax.mail.Session.getTransport(Session.java:661)
> >    at javax.mail.Session.getTransport(Session.java:641)
> >    at javax.mail.Session.getTransport(Session.java:696)
> >    at javax.mail.Transport.send0(Transport.java:186)
> >    at javax.mail.Transport.send(Transport.java:118)
> >    ...
> >
> > I found that the common/lib directory has javamail.jar file which is a
> > different version of JavaMail belongs to Tomcat in the production
> > environment and it causes the problem.  If I remove one of them, it
> > works yet I have to keep the libraries in my application as required by
> > my client, it must be designed to work in any Tomcat server with default
> > Tomcat libraries and the server admin also said he has to keep it there.
>
>
> So, your server admin needs it to be in common/lib and your client needs
> it to be in WEB-INF/lib?  Who does the server admin work for?
>
> Sounds like there's a conflict between the client spec and the server
> system provided - not your application.
>
>
>
> Jars in WEB-INF/lib should be loaded first, as servlet containers use an
> inverted classloader hierarchy.  Having said that, allowing duplicate
> jar files in the container usually ends in disaster, try not to do it.
>
> is it possible to persuade the server admin to upgrade the javamail
> install?
>
>
> p
>
>
>
> > So I would like to know if there is any way to choose which libraries to
> > use.  As it is in javax package, common/lib has higher priority I think.
> > Is there any way to change it so that my application uses JavaMail in
> > WEB-INF/lib instead of common/lib one?
> >
> > Regards,
> > Kevin
> >
> > ---------------------------------------------------------------------
> > To start a new topic, e-mail: users@tomcat.apache.org
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

Re: How can I use a class in javax package from the jar file in WEB-INF/lib instead of the one in common/lib.

Posted by Pid <p...@pidster.com>.
Kevin SeongHyun Lee wrote:
> Hello,
> 
> I'm trying to use JavaMail and the necessary libraries are in the
> WEB-INF/lib of my application. It works fine in my development
> environment. However, the problem is that after it is installed in the
> production environment and tries to send an email, it always throws
> NoSuchProviderException exception like the following lines.
> 
> javax.mail.NoSuchProviderException: smtp
>    at javax.mail.Session.getService(Session.java:794)
>    at javax.mail.Session.getTransport(Session.java:718)
>    at javax.mail.Session.getTransport(Session.java:661)
>    at javax.mail.Session.getTransport(Session.java:641)
>    at javax.mail.Session.getTransport(Session.java:696)
>    at javax.mail.Transport.send0(Transport.java:186)
>    at javax.mail.Transport.send(Transport.java:118)
>    ...
> 
> I found that the common/lib directory has javamail.jar file which is a
> different version of JavaMail belongs to Tomcat in the production
> environment and it causes the problem.  If I remove one of them, it
> works yet I have to keep the libraries in my application as required by
> my client, it must be designed to work in any Tomcat server with default
> Tomcat libraries and the server admin also said he has to keep it there.


So, your server admin needs it to be in common/lib and your client needs
it to be in WEB-INF/lib?  Who does the server admin work for?

Sounds like there's a conflict between the client spec and the server
system provided - not your application.



Jars in WEB-INF/lib should be loaded first, as servlet containers use an
inverted classloader hierarchy.  Having said that, allowing duplicate
jar files in the container usually ends in disaster, try not to do it.

is it possible to persuade the server admin to upgrade the javamail install?


p



> So I would like to know if there is any way to choose which libraries to
> use.  As it is in javax package, common/lib has higher priority I think.
> Is there any way to change it so that my application uses JavaMail in
> WEB-INF/lib instead of common/lib one?
> 
> Regards,
> Kevin
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


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