You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jon Pearson <Jo...@sixnet.com> on 2009/05/26 18:57:28 UTC

Classloaders

I'm having some trouble getting classes loaded by a new classloader to
be able to see classes which should have been loaded automatically from
WEB-INF/lib. All of the documentation that I've seen so far (FAQs,
mailing list searches, ...) describe problems that people have had using
the standard classloader that Tomcat provides, but I have yet to see one
dealing with dynamically loading classes from a new classloader defined
within a webapp.

More specifically, here is my problem:

I am developing an application suite involving a database backend which
feeds and is updated by server processes and a Web UI. To support
multiple databases, database modules (JAR files) can simply be dropped
in and loaded by each application dynamically.

The problem is that when the Web UI loads the database module, that
module is unable to actually load the JDBC driver
(org.postgresql.Driver) which is packaged in
WEB-INF/lib/postgresql-8.3-604.jdbc4.jar (I've checked the case of the
path components).

This is definitely related to classloaders; I tried placing the database
module directly into my WAR file under
WEB-INF/classes/package/name/PostgreSQLDatabale.class and it worked. But
if I do that, I lose the modularity and easy-upgrading that I achieved
by going with the dynamic loading of classes from JARs.

I'm using java.net.URLClassLoader with the parent classloader set to the
classloader that loaded my application classes, so it should
theoretically be the same classloader used to load the
postgresql-8.3-604.jdbc4.jar file.

Has anyone else encountered a problem like this? Any suggestions on what
else I should try? Thanks in advance!

Jonathan P. Pearson - Software Engineer
-------------------------------------------------- 
SIXNET - Solutions for Your Industrial Networking Challenges
331 Ushers Road, Ballston Lake, NY 12019
Tel: 1.518.877.5173, Fax: 1.518.877.8346
www.sixnet.com

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


RE: Classloaders

Posted by Jon Pearson <Jo...@sixnet.com>.
PS I tried using a different URL
(file:/etc/BlueVueBatch/BVBDatabases/PostgreSQLDatabase.jar) instead of
the weirdly formed one below, but I get the same error message. I guess
it will load the classes in that JAR either way, but (as I expected),
the format of the URL does not make a difference for access to other
classes.

> > > I'm guessing that:
> > >  * sun.misc.Launcher$ExtClassLoader is the bootstrap class loader
> > 
> > Not quite - the bootstrap class loader is null; the 
> > ExtClassLoader is the one that looks in the JRE's lib/ext directory.
> > 
> > >  * sun.misc.Launcher$AppClassLoader is the system class loader
> > >  * org.apache.catalina.loader.StandardClassLoader is the Tomcat
> > > 'common' class loader
> > >  * org.apache.catalina.loader.WebAppClassLoader is the 
> > Tomcat 'webapp'
> > > class loader for my project
> > >  * java.net.FactoryURLClassLoader is the class loader that 
> > I created to
> > > load classes out of my JAR plugin
> > 
> > Those four appear to be correct.
> > 
> > Can you determine the URLs supported by the last two?  Use 
> > the getURLs() API, or poke around in the JMX beans with JConsole.
> 
> java.net.FactoryURLClassLoader:
>  * jar:file:/etc/BlueVueBatch/BVBDatabases/PostgreSQLDatabase.jar!/
> 
> That's my plugin JAR. Should I be using a different URL format?
> 
> org.apache.catalina.loader.WebappClassLoader:
>  * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/classes/
>  * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/BVLib.jar
>  * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/Sixnet.jar
>  *
> file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/antlr-runtime-
> 3.1.2.jar
>  *
> file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/commons-fileup
> load-1.2.1
> .jar
>  * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/commons-io-1.4.jar
>  *
> file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/commons-loggin
> g-1.0.4.ja
> r
>  * 
> file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/freemarker-2.3.13.jar
>  * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/log4j-1.2.15.jar
>  * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/ognl-2.6.11.jar
>  *
> file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/postgresql-8.3
> -604.jdbc4
> .jar
>  *
> file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/struts2-core-2.1.6.jar
>  * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/xwork-2.1.2.jar
> 
> Third up from the bottom is the one that provides 
> org.postgresql.Driver
> 
> ~Jonathan
> 
> ---------------------------------------------------------------------
> 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: Classloaders

Posted by Jon Pearson <Jo...@sixnet.com>.
> > I'm guessing that:
> >  * sun.misc.Launcher$ExtClassLoader is the bootstrap class loader
> 
> Not quite - the bootstrap class loader is null; the 
> ExtClassLoader is the one that looks in the JRE's lib/ext directory.
> 
> >  * sun.misc.Launcher$AppClassLoader is the system class loader
> >  * org.apache.catalina.loader.StandardClassLoader is the Tomcat
> > 'common' class loader
> >  * org.apache.catalina.loader.WebAppClassLoader is the 
> Tomcat 'webapp'
> > class loader for my project
> >  * java.net.FactoryURLClassLoader is the class loader that 
> I created to
> > load classes out of my JAR plugin
> 
> Those four appear to be correct.
> 
> Can you determine the URLs supported by the last two?  Use 
> the getURLs() API, or poke around in the JMX beans with JConsole.

java.net.FactoryURLClassLoader:
 * jar:file:/etc/BlueVueBatch/BVBDatabases/PostgreSQLDatabase.jar!/

That's my plugin JAR. Should I be using a different URL format?

org.apache.catalina.loader.WebappClassLoader:
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/classes/
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/BVLib.jar
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/Sixnet.jar
 *
file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/antlr-runtime-3.1.2.jar
 *
file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/commons-fileupload-1.2.1
.jar
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/commons-io-1.4.jar
 *
file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/commons-logging-1.0.4.ja
r
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/freemarker-2.3.13.jar
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/log4j-1.2.15.jar
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/ognl-2.6.11.jar
 *
file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/postgresql-8.3-604.jdbc4
.jar
 *
file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/struts2-core-2.1.6.jar
 * file:/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/xwork-2.1.2.jar

Third up from the bottom is the one that provides org.postgresql.Driver

~Jonathan

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


RE: Classloaders

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jon Pearson [mailto:Jon.Pearson@sixnet.com]
> Subject: RE: Classloaders
> 
> I'm guessing that:
>  * sun.misc.Launcher$ExtClassLoader is the bootstrap class loader

Not quite - the bootstrap class loader is null; the ExtClassLoader is the one that looks in the JRE's lib/ext directory.

>  * sun.misc.Launcher$AppClassLoader is the system class loader
>  * org.apache.catalina.loader.StandardClassLoader is the Tomcat
> 'common' class loader
>  * org.apache.catalina.loader.WebAppClassLoader is the Tomcat 'webapp'
> class loader for my project
>  * java.net.FactoryURLClassLoader is the class loader that I created to
> load classes out of my JAR plugin

Those four appear to be correct.

Can you determine the URLs supported by the last two?  Use the getURLs() API, or poke around in the JMX beans with JConsole.

 - 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 unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Classloaders

Posted by Jon Pearson <Jo...@sixnet.com>.
> >> 2. The documentation on classloaders is here:
> >> http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
> >
> > Thanks, but I've read through that a few times. It describes the
> > existing classloader layout but does not describe how to 
> avoid problems
> > when using your own within Tomcat.
> >
> 
> Well, at least you should cooperate with this layout. ;)

As far as I know, I am. I was using the classloader of the current class as the parent when constructing the URLClassLoader, now I am using Thread.currentThread().getContextClassloader() (although this did not solve the problem).

> Some notes:
> 
> The class loader of a web application can be retrieved as
> Thread#getContextClassLoader()

Just tried this, didn't help. But it seems like the proper thing to do, so I'll leave it in.

> Also, if you run in development mode (see Jasper 
> configuration), each JSP
> is executed with its own class loader, so that they can be reloaded.
> http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html

I don't think I've even gotten to a JSP yet; I'm running with Struts2, and the first thing that the action tries to do is connect to the database.

> >> 4. Put the jar file into WEB-INF/lib, and then restart your
> >> web application.
> >>  (E.g., using Tomcat Manager).  Your jar library will be loaded.
> >> http://tomcat.apache.org/tomcat-6.0-doc/html-manager-howto.html
> >> http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html
> >
> > It is more of a plugin than a library. The location is 
> user-specified, a
> > directory to watch for plugin JARs. Each JAR contains 
> metadata in the
> > manifest describing the main class of the plugin. That main class is
> > loaded using Class.forName(), causing a static{} block in 
> the class to
> > run, performing any registrations necessary to integrate with the
> > application.
> >
> > When the class is needed (i.e. when I try to connect to a 
> database), a
> > new instance is created. That involves calling Class.forName()
> 
> Do you pass a ClassLoader reference to that forName() call?
> What is classloader hierarchy for the ClassLoader used by that call?

sun.misc.Launcher$ExtClassLoader --> sun.misc.Launcher$AppClassLoader --> org.apache.catalina.loader.StandardClassLoader --> org.apache.catalina.loader.WebAppClassLoader --> java.net.FactoryURLClassLoader

I'm guessing that:
 * sun.misc.Launcher$ExtClassLoader is the bootstrap class loader
 * sun.misc.Launcher$AppClassLoader is the system class loader
 * org.apache.catalina.loader.StandardClassLoader is the Tomcat 'common' class loader
 * org.apache.catalina.loader.WebAppClassLoader is the Tomcat 'webapp' class loader for my project
 * java.net.FactoryURLClassLoader is the class loader that I created to load classes out of my JAR plugin

I was not passing a classloader to the Class.forName() call (to load org.postgresql.Driver), but when I call

  Class.forName("org.postgresql.Driver", true, PostgreSQLDatabase.class.getClassLoader())

I still see the same result -- "java.lang.ClassNotFoundException: org.postgresql.Driver". Also, I checked which classloader PostgreSQLDatabase.class.getClassLoader() was and it is the URLClassLoader like I expected.

I also tried using Thread.currentThread.getContextClassLoader() (which is the Webapp classloader, I checked) for the Class.forName call, but I got the same result.

> See
> http://java.sun.com/javase/6/docs/api/java/lang/Class.html#for
> Name(java.lang.String)
> http://java.sun.com/javase/6/docs/api/java/lang/Class.html#for
> Name(java.lang.String,%20boolean,%20java.lang.ClassLoader)
> 
> > to load
> > the PostgreSQL database driver (a class called 
> 'org.postgresql.Driver'),
> > contained in postgresql-8.3-604.jdbc4.jar (present in 
> WEB-INF/lib). But
> > that call to Class.forName() to load org.postgresql.Driver 
> fails because
> > the class cannot be found.
> >
> > This is confounding because an ancestor classloader of my 
> URLClassLoader
> > that made the classes in my plugin JAR available should 
> have access to
> > org.postgresql.Driver. In fact, one of them *must* because when the
> > classes in my plugin JAR are placed into WEB-INF/classes in 
> their raw
> > .class state (not packaged into a jar), everything works.
> >
> 
> It might be. What happens, step-by-step, in this case?  Additional
> classes will be picked up by web-app classloader instantly. Additional
> JARs - only upon restart of the web application, because it requires
> reconfiguration of the class loader (adds additional URLs to scan for
> classes).

When the classes are in WEB-INF/classes (instead of in a plugin JAR), here is a step-by-step:
 1) I modify the configuration file that specifies where plugin classes come from. The two options are:
    a) Built-into the application, just use Class.forName(String)
    b) In plugin JARs, either specified as individual JAR files or as a directory to watch for JARs
 2) When the app starts, it loads the configuration file. Since the config specifies that the classes are built into the app, it calls Class.forName(String) on each specified class name
 3) I request a new database for the provider specified in the configuration file (PostgreSQL in this case) and, assuming it was constructed successfully, I use it to connect to the database. This works here, but fails using the other method.

When the classes are in separate plugin JARs:
 1) I modify the configuration file to point to the specific JAR (I could point it at a directory, but this is more straightforward)
 2) When the app starts, it loads the configuration file. The config specifies a plugin JAR to load, so I read the metadata out of the jar to check
    a) Is it a plugin
    b) What is the class in that plugin that needs to be initialized (to register itself appropriately)
 3) I then construct a new URLClassLoader that points at that jar
 4) I call Class.forName(name of the main plugin class, true, the new URLClassLoader) to initialize the class and allow it to perform its registration
 5) I request a new database... This is where it fails, because the constructor of PostgreSQLDatabase (my main plugin class) is unable to load 'org.postgresql.Driver' using Class.forName() (either version).

I have been re-deploying the webapp, or copying the plugins and restarting Tomcat any time I make a change, so there is no class loader reconfiguration going in. When I tested with the classes in WEB-INF/classes, I hand-edited the WAR to place those classes there and then re-deployed.

> Best regards,
> Konstantin Kolinko

~Jonathan Pearson

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


Re: Classloaders

Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/5/27 Jon Pearson <Jo...@sixnet.com>:
>> -----Original Message-----
>> From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com]
>> Sent: Tuesday, May 26, 2009 4:44 PM
>> To: Tomcat Users List
>> Subject: Re: Classloaders
>>
>> 1. What tomcat version?
>
> Tomcat v. 6.0.18, JVM 1.6.0_13, Ubuntu 9.04 on kernel 2.6.28-11
>

OK

>> 2. The documentation on classloaders is here:
>> http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html
>
> Thanks, but I've read through that a few times. It describes the
> existing classloader layout but does not describe how to avoid problems
> when using your own within Tomcat.
>

Well, at least you should cooperate with this layout. ;)


Some notes:

The class loader of a web application can be retrieved as
Thread#getContextClassLoader()

Also, if you run in development mode (see Jasper configuration), each JSP
is executed with its own class loader, so that they can be reloaded.
http://tomcat.apache.org/tomcat-6.0-doc/jasper-howto.html

>> 3. Some JDBC drivers use native code. Those cannot be loaded from
>> different class loaders in the same time. Thus, they cannot be loaded
>> from /WEB-INF/lib, as there will be conflicts between applications,
>> or between several instances of the same application if it is
>> restarted.
>
> This one does not include any native code, it is self-contained in a
> single JAR file.
>
>> 4. Put the jar file into WEB-INF/lib, and then restart your
>> web application.
>>  (E.g., using Tomcat Manager).  Your jar library will be loaded.
>> http://tomcat.apache.org/tomcat-6.0-doc/html-manager-howto.html
>> http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html
>
> It is more of a plugin than a library. The location is user-specified, a
> directory to watch for plugin JARs. Each JAR contains metadata in the
> manifest describing the main class of the plugin. That main class is
> loaded using Class.forName(), causing a static{} block in the class to
> run, performing any registrations necessary to integrate with the
> application.
>
> When the class is needed (i.e. when I try to connect to a database), a
> new instance is created. That involves calling Class.forName()

Do you pass a ClassLoader reference to that forName() call?
What is classloader hierarchy for the ClassLoader used by that call?

See
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#forName(java.lang.String)
http://java.sun.com/javase/6/docs/api/java/lang/Class.html#forName(java.lang.String,%20boolean,%20java.lang.ClassLoader)

> to load
> the PostgreSQL database driver (a class called 'org.postgresql.Driver'),
> contained in postgresql-8.3-604.jdbc4.jar (present in WEB-INF/lib). But
> that call to Class.forName() to load org.postgresql.Driver fails because
> the class cannot be found.
>
> This is confounding because an ancestor classloader of my URLClassLoader
> that made the classes in my plugin JAR available should have access to
> org.postgresql.Driver. In fact, one of them *must* because when the
> classes in my plugin JAR are placed into WEB-INF/classes in their raw
> .class state (not packaged into a jar), everything works.
>

It might be. What happens, step-by-step, in this case?  Additional
classes will be picked up by web-app classloader instantly. Additional
JARs - only upon restart of the web application, because it requires
reconfiguration of the class loader (adds additional URLs to scan for
classes).

Best regards,
Konstantin Kolinko

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


RE: Classloaders

Posted by Jon Pearson <Jo...@sixnet.com>.
> > From: Jon Pearson [mailto:Jon.Pearson@sixnet.com]
> > Subject: RE: Classloaders
> > 
> > This is confounding because an ancestor classloader of my
> > URLClassLoader that made the classes in my plugin JAR 
> > available should have access to org.postgresql.Driver.
> > In fact, one of them *must* because when the classes in
> > my plugin JAR are placed into WEB-INF/classes in their raw
> > .class state (not packaged into a jar), everything works.
> 
> Is there any possibility that the class of interest is in two 
> places?  When you put the jar into WEB-INF/lib, do you remove 
> it from WEB-INF/classes?
> 
>  - Chuck

It is definitely not in WEB-INF/classes.

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


RE: Classloaders

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Jon Pearson [mailto:Jon.Pearson@sixnet.com]
> Subject: RE: Classloaders
> 
> This is confounding because an ancestor classloader of my
> URLClassLoader that made the classes in my plugin JAR 
> available should have access to org.postgresql.Driver.
> In fact, one of them *must* because when the classes in
> my plugin JAR are placed into WEB-INF/classes in their raw
> .class state (not packaged into a jar), everything works.

Is there any possibility that the class of interest is in two places?  When you put the jar into WEB-INF/lib, do you remove it from WEB-INF/classes?

 - 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 unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Classloaders

Posted by Jon Pearson <Jo...@sixnet.com>.
> -----Original Message-----
> From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com] 
> Sent: Tuesday, May 26, 2009 4:44 PM
> To: Tomcat Users List
> Subject: Re: Classloaders
> 
> 1. What tomcat version?

Tomcat v. 6.0.18, JVM 1.6.0_13, Ubuntu 9.04 on kernel 2.6.28-11

> 2. The documentation on classloaders is here:
> http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

Thanks, but I've read through that a few times. It describes the
existing classloader layout but does not describe how to avoid problems
when using your own within Tomcat.

> 3. Some JDBC drivers use native code. Those cannot be loaded from
> different class loaders in the same time. Thus, they cannot be loaded
> from /WEB-INF/lib, as there will be conflicts between applications,
> or between several instances of the same application if it is 
> restarted.

This one does not include any native code, it is self-contained in a
single JAR file.

> 4. Put the jar file into WEB-INF/lib, and then restart your 
> web application.
>  (E.g., using Tomcat Manager).  Your jar library will be loaded.
> http://tomcat.apache.org/tomcat-6.0-doc/html-manager-howto.html
> http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html

It is more of a plugin than a library. The location is user-specified, a
directory to watch for plugin JARs. Each JAR contains metadata in the
manifest describing the main class of the plugin. That main class is
loaded using Class.forName(), causing a static{} block in the class to
run, performing any registrations necessary to integrate with the
application.

When the class is needed (i.e. when I try to connect to a database), a
new instance is created. That involves calling Class.forName() to load
the PostgreSQL database driver (a class called 'org.postgresql.Driver'),
contained in postgresql-8.3-604.jdbc4.jar (present in WEB-INF/lib). But
that call to Class.forName() to load org.postgresql.Driver fails because
the class cannot be found.

This is confounding because an ancestor classloader of my URLClassLoader
that made the classes in my plugin JAR available should have access to
org.postgresql.Driver. In fact, one of them *must* because when the
classes in my plugin JAR are placed into WEB-INF/classes in their raw
.class state (not packaged into a jar), everything works.

> Best regards,
> Konstantin Kolinko


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


Re: Classloaders

Posted by Konstantin Kolinko <kn...@gmail.com>.
2009/5/26 Jon Pearson <Jo...@sixnet.com>:
> I'm having some trouble getting classes loaded by a new classloader to
> be able to see classes which should have been loaded automatically from
> WEB-INF/lib. All of the documentation that I've seen so far (FAQs,
> mailing list searches, ...) describe problems that people have had using
> the standard classloader that Tomcat provides, but I have yet to see one
> dealing with dynamically loading classes from a new classloader defined
> within a webapp.
>
> More specifically, here is my problem:
>
> I am developing an application suite involving a database backend which
> feeds and is updated by server processes and a Web UI. To support
> multiple databases, database modules (JAR files) can simply be dropped
> in and loaded by each application dynamically.
>
> The problem is that when the Web UI loads the database module, that
> module is unable to actually load the JDBC driver
> (org.postgresql.Driver) which is packaged in
> WEB-INF/lib/postgresql-8.3-604.jdbc4.jar (I've checked the case of the
> path components).
>
> This is definitely related to classloaders; I tried placing the database
> module directly into my WAR file under
> WEB-INF/classes/package/name/PostgreSQLDatabale.class and it worked. But
> if I do that, I lose the modularity and easy-upgrading that I achieved
> by going with the dynamic loading of classes from JARs.
>
> I'm using java.net.URLClassLoader with the parent classloader set to the
> classloader that loaded my application classes, so it should
> theoretically be the same classloader used to load the
> postgresql-8.3-604.jdbc4.jar file.
>
> Has anyone else encountered a problem like this? Any suggestions on what
> else I should try? Thanks in advance!
>
> Jonathan P. Pearson - Software Engineer
> --------------------------------------------------

1. What tomcat version?

2. The documentation on classloaders is here:
http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html

3. Some JDBC drivers use native code. Those cannot be loaded from
different class loaders in the same time. Thus, they cannot be loaded
from /WEB-INF/lib, as there will be conflicts between applications,
or between several instances of the same application if it is restarted.

4. Put the jar file into WEB-INF/lib, and then restart your web application.
 (E.g., using Tomcat Manager).  Your jar library will be loaded.
http://tomcat.apache.org/tomcat-6.0-doc/html-manager-howto.html
http://tomcat.apache.org/tomcat-6.0-doc/manager-howto.html

Best regards,
Konstantin Kolinko

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