RE: Classloader Issues (SOLVED)

2009-06-11 Thread Jon Pearson
Apparently there was some kind of silent failure going on behind the
scenes. It seems that the dynamically loaded JAR needed filesystem read
access to the JAR in WEB-INF/lib, and that both the webapp and the other
JAR needed to have java.net.SocketPermission for connect and resolve
against the database server.

Not sure why this manifested itself as a ClassNotFoundException instead
of a SecurityException telling me that I can't read the PostgreSQL
Driver JAR...

Thanks for your help, everyone!

> -Original Message-
> From: Jon Pearson 
> Sent: Thursday, June 11, 2009 1:14 PM
> To: Tomcat Users List
> Subject: Classloader Issues
> 
> I am encountering an odd problem with Tomcat (6.0.18). When the Java
> security manager is enabled, I get a ClassNotFoundException when I try
> to load the Postgres database driver using Class.forName() and a URL
> classloader pointed at a jar; its parent classloader is the Webapp
> classloader.
> 
> But, when the Java security manager is disabled, everything works
> smoothly and no ClassNotFoundException is thrown.
> 
> I've stepped through the code (using Eclipse's debugger) and not found
> anything that stands out, and I've set a general breakpoint on all
> SecurityExceptions, caught or uncaught. None are thrown.
> 
> Has anyone else encountered a problem like this? Is there a 
> way for the
> Java security manager to block a class from loading without a
> SecurityException being thrown?
> 
> 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-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 

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



RE: Classloader Issues

2009-06-11 Thread Jon Pearson
My last message included the stack trace. The Postgresql jar is in the
WEB-INF/lib directory of my webapp
(/var/lib/tomcat6/webapps/BVWeb/WEB-INF/lib/postgresql-8.3-604.jdbc4.jar
on Linux,
C:\Projects\Java\Eclipse\.metadata\.plugins\org.eclipse.wst.server.core\
tmp1\webapps\BVWeb\WEB-INF\lib\postgresql-8.3-604.jdbc4.jar on Windows).

Also, here is the relevant section of my catalina.policy file for
Windows:

grant codeBase "file:${catalina.base}/webapps/BVWeb/-" {
permission java.util.PropertyPermission "*", "read";

permission java.io.FilePermission "${user.home}/Application
Data/BlueVueBatch/-", "read";
permission java.io.FilePermission "C:/Documents and Settings/All
Users/Application Data/BlueVueBatch/-", "read";
permission java.io.FilePermission "${bvb.databases}/-", "read";
permission java.io.FilePermission
"${catalina.base}/work/Catalina/localhost/BVWeb/-", "write";
permission java.io.FilePermission "template/-", "read";

permission java.lang.reflect.ReflectPermission
"suppressAccessChecks";
permission java.lang.RuntimePermission "getenv.APPDATA";
permission java.lang.RuntimePermission "getenv.ALLUSERSPROFILE";
permission java.lang.RuntimePermission "getenv.USERNAME";
permission java.lang.RuntimePermission "getClassLoader";
permission java.net.SocketPermission "*", "connect,resolve";
permission java.lang.RuntimePermission "accessDeclaredMembers";
permission ognl.OgnlInvokePermission "*";
};


And for Linux:

// These permissions are granted to the BlueVueBatch Web UI application

grant codeBase "file:${catalina.base}/webapps/BVWeb/-" {
permission java.io.FilePermission "${user.home}/.bvb/-",
"read";
permission java.io.FilePermission "/etc/BlueVueBatch/-",
"read";
permission java.io.FilePermission
"${catalina.base}/work/Catalina/localhost/BlueVueWeb/-", "write";
permission java.io.FilePermission "template/-",
"read";

permission java.lang.reflect.ReflectPermission
"suppressAccessChecks";

permission java.lang.RuntimePermission "getClassLoader";
permission java.lang.RuntimePermission "accessDeclaredMembers";

permission java.net.SocketPermission "*", "connect,resolve";

permission java.util.PropertyPermission "*", "read";

permission ognl.OgnlInvokePermission "*";

// For logging
permission java.io.FilePermission "/var/log/tomcat6/*",
"read,write,delete";
};

// Allow the Database plugins to load properly
grant codeBase "file:/etc/BlueVueBatch/BVBDatabases/-" {
permission java.lang.RuntimePermission "getClassLoader";
};


 

> -Original Message-
> From: Caldarale, Charles R [mailto:chuck.caldar...@unisys.com] 
> Sent: Thursday, June 11, 2009 3:20 PM
> To: Tomcat Users List
> Subject: RE: Classloader Issues
> 
> > From: Jon Pearson [mailto:jon.pear...@sixnet.com]
> > Subject: RE: Classloader Issues
> > 
> > That blurb was already in the catalina.policy file.
> 
> I think Martin was just using that as an example; you likely 
> need to grant some permission(s) to your own classloader code.
> 
> Again, posting the stack trace and the location of the MySQL 
> jar would help to diagnose your problem.
> 
>  - 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-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 

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



RE: Classloader Issues

2009-06-11 Thread Jon Pearson
)
 
org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(Servle
tConfigInterceptor.java:164)
 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvo
cation.java:236)
 
com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInte
rceptor.java:128)
 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvo
cation.java:236)
 
com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercep
t(ExceptionMappingInterceptor.java:176)
 
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvo
cation.java:236)
 
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java
:52)
 
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:4
68)
 
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher
.java:395)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
 
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Unknown Source)
 
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
 
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.jav
a:218)
 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applica
tionFilterChain.java:230)
 
org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFi
lterChain.java:56)
 
org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterC
hain.java:189)
java.security.AccessController.doPrivileged(Native Method)
 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilt
erChain.java:185)
 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValv
e.java:233)
 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValv
e.java:191)
 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java
:128)
 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java
:102)
 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.
java:109)
 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:2
86)
 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:84
5)
 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(
Http11Protocol.java:583)
 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
java.lang.Thread.run(Unknown Source)

 
The jar containing the class that then loads the PostgreSQL driver is in
/etc/BlueVueBatch/BVBDatabases/PostgreSQLDatabase.jar on Linux (Ubuntu
9.04), and it is in
C:\Projects\Java\Eclipse\dist\BVBDatabases\PostgreSQLDatabase.jar on
Windows XP. I see the same problem on both operating systems.

> -Original Message-
> From: Caldarale, Charles R [mailto:chuck.caldar...@unisys.com] 
> Sent: Thursday, June 11, 2009 2:21 PM
> To: Tomcat Users List
> Subject: RE: Classloader Issues
> 
> > From: Jon Pearson [mailto:jon.pear...@sixnet.com]
> > Subject: Classloader Issues
> > 
> > When the Java security manager is enabled, I get a 
> > ClassNotFoundException when I try to load the Postgres
> > database driver using Class.forName() and a URL
> > classloader pointed at a jar; its parent classloader
> > is the Webapp classloader.
> 
> Stack trace?  (Please post.)
> 
> Location of the jar of interest?  (Please specify.)
> 
>  - 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-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 

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



RE: Classloader Issues

2009-06-11 Thread Jon Pearson
That blurb was already in the catalina.policy file.

> -Original Message-
> From: Martin Gainty [mailto:mgai...@hotmail.com] 
> Sent: Thursday, June 11, 2009 2:39 PM
> To: Tomcat Users List
> Subject: RE: Classloader Issues
> 
> 
> inside TC you have to grant the container access to Jar 
> assuming your class is located in commons-daemon.jar in 
> $CATALINA_HOME/conf/catalina.policy
> 
> // These permissions apply to the daemon code
> grant codeBase "file:${catalina.home}/bin/commons-daemon.jar" {
> permission java.security.AllPermission;
> };
> 
> HTH!
> Martin Gainty 
> __ 
> Verzicht und Vertraulichkeitanmerkung/Note de déni et de 
> confidentialité
>  
> Diese Nachricht ist vertraulich. Sollten Sie nicht der 
> vorgesehene Empfaenger sein, so bitten wir hoeflich um eine 
> Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer 
> Kopie ist unzulaessig. Diese Nachricht dient lediglich dem 
> Austausch von Informationen und entfaltet keine rechtliche 
> Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von 
> E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
> Ce message est confidentiel et peut être privilégié. Si vous 
> n'êtes pas le destinataire prévu, nous te demandons avec 
> bonté que pour satisfaire informez l'expéditeur. N'importe 
> quelle diffusion non autorisée ou la copie de ceci est 
> interdite. Ce message sert à l'information seulement et 
> n'aura pas n'importe quel effet légalement obligatoire. Étant 
> donné que les email peuvent facilement être sujets à la 
> manipulation, nous ne pouvons accepter aucune responsabilité 
> pour le contenu fourni.
> 
> 
> 
> 
> > Subject: Classloader Issues
> > Date: Thu, 11 Jun 2009 13:13:32 -0400
> > From: jon.pear...@sixnet.com
> > To: users@tomcat.apache.org
> > 
> > I am encountering an odd problem with Tomcat (6.0.18). When the Java
> > security manager is enabled, I get a ClassNotFoundException 
> when I try
> > to load the Postgres database driver using Class.forName() and a URL
> > classloader pointed at a jar; its parent classloader is the Webapp
> > classloader.
> > 
> > But, when the Java security manager is disabled, everything works
> > smoothly and no ClassNotFoundException is thrown.
> > 
> > I've stepped through the code (using Eclipse's debugger) 
> and not found
> > anything that stands out, and I've set a general breakpoint on all
> > SecurityExceptions, caught or uncaught. None are thrown.
> > 
> > Has anyone else encountered a problem like this? Is there a 
> way for the
> > Java security manager to block a class from loading without a
> > SecurityException being thrown?
> > 
> > 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-unsubscr...@tomcat.apache.org
> > For additional commands, e-mail: users-h...@tomcat.apache.org
> > 
> 
> _
> Insert movie times and more without leaving Hotmail®. 
> http://windowslive.com/Tutorial/Hotmail/QuickAdd?ocid=TXT_TAGL
> M_WL_HM_Tutorial_QuickAdd_062009
> 

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



Classloader Issues

2009-06-11 Thread Jon Pearson
I am encountering an odd problem with Tomcat (6.0.18). When the Java
security manager is enabled, I get a ClassNotFoundException when I try
to load the Postgres database driver using Class.forName() and a URL
classloader pointed at a jar; its parent classloader is the Webapp
classloader.

But, when the Java security manager is disabled, everything works
smoothly and no ClassNotFoundException is thrown.

I've stepped through the code (using Eclipse's debugger) and not found
anything that stands out, and I've set a general breakpoint on all
SecurityExceptions, caught or uncaught. None are thrown.

Has anyone else encountered a problem like this? Is there a way for the
Java security manager to block a class from loading without a
SecurityException being thrown?

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



RE: Classloaders

2009-05-27 Thread Jon Pearson
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-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
> 
> 

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



RE: Classloaders

2009-05-27 Thread Jon Pearson
> > 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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Classloaders

2009-05-27 Thread Jon Pearson
> >> 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 f

RE: Classloaders

2009-05-27 Thread Jon Pearson
> > From: Jon Pearson [mailto:jon.pear...@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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



RE: Classloaders

2009-05-26 Thread Jon Pearson
> -Original Message-
> From: Konstantin Kolinko [mailto:knst.koli...@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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Classloaders

2009-05-26 Thread Jon Pearson
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-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org