You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Simon Kitching <sk...@apache.org> on 2005/03/19 05:44:40 UTC

Delegate flag for classloading (ATTN: Remy Maucherat)

Hi,

I see here that there is an option for the webapp-specific classloader
to use parent-first classloading instead of the (default) child-first
classloading.

Can someone suggest why this might be useful? Clearly someone thought
so, but I can't see any point in it. It is in catalina since version 1.1
(committer: Remy Maucherat).

See "delegate" option in this page:
  http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/loader.html

Using this option makes life exceedingly complicated for some libs like
commons-beanutils and commons-logging, so I would like to know under
what conditions someone might enable this feature.

Regards,

Simon


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


Re: No bug with Delegate !

Posted by David Smith <dn...@cornell.edu>.
If you want to use the .jar in WEB-INF/lib, you'll also have to 
implement your own DBCP pool for the app.  That can be done in a 
ServletContextListener in servlet spec 2.4.  When the container 
instantiates the pool, it's always going to use the jar in common/lib 
(or possibly shared/lib) because it's instantiated at the container 
level.  At that level there is no awareness of you apps classloader.

--David

Lionel Farbos wrote:

>Hi,
>
>Sorry but my preceding analysis was false : I have a problem but NOT with the delegate.
>So, I reexplain the case :
>
>1- I have 
>$CATALINA_HOME/common/lib/mysql-connector-java-2.0.14-bin.jar
>$CATALINA_HOME/common/lib/naming-factory-dbcp.jar
>2- I have a war with
>WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar
>WEB-INF/lib/naming-factory-dbcp.jar
>
>in my test, I do :
>Class driver = Class.forName("org.gjt.mm.mysql.Driver");
>URL ressource = driver.getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");
>out.println( "ClassForname==>"+ressource );
>
>If, in my Context element, I put a Loader with delegate=false (the default), it prints : 
>ClassForname==>jar:file:/usr/local/tomcat/webapps/myContext/WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar!/org/gjt/mm/mysql/Driver.class
>
>If I put delegate=true, it prints :
>ClassForname==>jar:file:/usr/local/tomcat/common/lib/mysql-connector-java-2.0.14-bin.jar!/org/gjt/mm/mysql/Driver.class
>
>So delegate works as it is expected.
>
>My problem is that, in my first test, I did :
>Context ctx = new InitialContext();
>DataSource dataSource = (DataSource)ctx.lookup("java:/comp/env/jdbc/myDB");
>URL ressource = dataSource.getClass().getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");
>out.println( "JndiForname==>"+ressource );
>
>and, in this case, I always have :
>ClassForname==>jar:file:/usr/local/tomcat/common/lib/mysql-connector-java-2.0.14-bin.jar!/org/gjt/mm/mysql/Driver.class
>
>So, for now, I don't find the solution to use the Driver inside the war :-(
>But this is another problem...
>
>Sorry Remy for the bad bug report.
>
>On Wed, 23 Mar 2005 17:26:34 +0100
>Lionel Farbos <li...@free.fr> wrote:
>
>  
>
>>Hi Simon,
>>
>>I wanted to use this flag because, in my $CATALINA_HOME/common/lib,
>>I have mysql-connector-java-2.0.14-bin.jar
>>but, 
>>in some wars, I have 
>>WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar
>>WEB-INF/lib/naming-factory-dbcp.jar
>>and in other wars, I don't have any Driver Mysql
>>
>>So, I'd want the war_WEB-INF/lib/<Mysql_jar> to be taken BEFORE the common/lib/<Mysql_jar> one when it is possible
>>and
>>the common/lib/<Mysql_jar> to be taken in other cases.
>>
>>So I tried to put 
>><Loader className="org.apache.catalina.loader.WebappLoader" delegate="false" />
>>or 
>><Loader className="org.apache.catalina.loader.WebappLoader" delegate="true" />
>>in my Context.xml
>>But it is always the common/lib/jar one which is taken :-((
>>
>>I don't know if it is a bug or a bad config from me ....
>>
>>If a Tomcat Developer can say to me what I am wrong ...
>>
>>Note : To confirm the Driver version, I print :
>>dataSource.getClass().getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");
>>
>>Cheers
>>On Sat, 19 Mar 2005 17:44:40 +1300
>>Simon Kitching <sk...@apache.org> wrote:
>>
>>    
>>
>>>Hi,
>>>
>>>I see here that there is an option for the webapp-specific classloader
>>>to use parent-first classloading instead of the (default) child-first
>>>classloading.
>>>
>>>Can someone suggest why this might be useful? Clearly someone thought
>>>so, but I can't see any point in it. It is in catalina since version 1.1
>>>(committer: Remy Maucherat).
>>>
>>>See "delegate" option in this page:
>>>  http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/loader.html
>>>
>>>Using this option makes life exceedingly complicated for some libs like
>>>commons-beanutils and commons-logging, so I would like to know under
>>>what conditions someone might enable this feature.
>>>
>>>Regards,
>>>
>>>Simon
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>>
>>>
>>>      
>>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>  
>

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


Re: No bug with Delegate !

Posted by Lionel Farbos <li...@free.fr>.
Hi,

Sorry but my preceding analysis was false : I have a problem but NOT with the delegate.
So, I reexplain the case :

1- I have 
$CATALINA_HOME/common/lib/mysql-connector-java-2.0.14-bin.jar
$CATALINA_HOME/common/lib/naming-factory-dbcp.jar
2- I have a war with
WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar
WEB-INF/lib/naming-factory-dbcp.jar

in my test, I do :
Class driver = Class.forName("org.gjt.mm.mysql.Driver");
URL ressource = driver.getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");
out.println( "ClassForname==>"+ressource );

If, in my Context element, I put a Loader with delegate=false (the default), it prints : 
ClassForname==>jar:file:/usr/local/tomcat/webapps/myContext/WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar!/org/gjt/mm/mysql/Driver.class

If I put delegate=true, it prints :
ClassForname==>jar:file:/usr/local/tomcat/common/lib/mysql-connector-java-2.0.14-bin.jar!/org/gjt/mm/mysql/Driver.class

So delegate works as it is expected.

My problem is that, in my first test, I did :
Context ctx = new InitialContext();
DataSource dataSource = (DataSource)ctx.lookup("java:/comp/env/jdbc/myDB");
URL ressource = dataSource.getClass().getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");
out.println( "JndiForname==>"+ressource );

and, in this case, I always have :
ClassForname==>jar:file:/usr/local/tomcat/common/lib/mysql-connector-java-2.0.14-bin.jar!/org/gjt/mm/mysql/Driver.class

So, for now, I don't find the solution to use the Driver inside the war :-(
But this is another problem...

Sorry Remy for the bad bug report.

On Wed, 23 Mar 2005 17:26:34 +0100
Lionel Farbos <li...@free.fr> wrote:

> Hi Simon,
> 
> I wanted to use this flag because, in my $CATALINA_HOME/common/lib,
> I have mysql-connector-java-2.0.14-bin.jar
> but, 
> in some wars, I have 
> WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar
> WEB-INF/lib/naming-factory-dbcp.jar
> and in other wars, I don't have any Driver Mysql
> 
> So, I'd want the war_WEB-INF/lib/<Mysql_jar> to be taken BEFORE the common/lib/<Mysql_jar> one when it is possible
> and
> the common/lib/<Mysql_jar> to be taken in other cases.
> 
> So I tried to put 
> <Loader className="org.apache.catalina.loader.WebappLoader" delegate="false" />
> or 
> <Loader className="org.apache.catalina.loader.WebappLoader" delegate="true" />
> in my Context.xml
> But it is always the common/lib/jar one which is taken :-((
> 
> I don't know if it is a bug or a bad config from me ....
> 
> If a Tomcat Developer can say to me what I am wrong ...
> 
> Note : To confirm the Driver version, I print :
> dataSource.getClass().getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");
> 
> Cheers
> On Sat, 19 Mar 2005 17:44:40 +1300
> Simon Kitching <sk...@apache.org> wrote:
> 
> > Hi,
> > 
> > I see here that there is an option for the webapp-specific classloader
> > to use parent-first classloading instead of the (default) child-first
> > classloading.
> > 
> > Can someone suggest why this might be useful? Clearly someone thought
> > so, but I can't see any point in it. It is in catalina since version 1.1
> > (committer: Remy Maucherat).
> > 
> > See "delegate" option in this page:
> >   http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/loader.html
> > 
> > Using this option makes life exceedingly complicated for some libs like
> > commons-beanutils and commons-logging, so I would like to know under
> > what conditions someone might enable this feature.
> > 
> > Regards,
> > 
> > Simon
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> > 
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

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


Re: bug with Delegate ?

Posted by Lionel Farbos <li...@free.fr>.
Hi Simon,

I wanted to use this flag because, in my $CATALINA_HOME/common/lib,
I have mysql-connector-java-2.0.14-bin.jar
but, 
in some wars, I have 
WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar
WEB-INF/lib/naming-factory-dbcp.jar
and in other wars, I don't have any Driver Mysql

So, I'd want the war_WEB-INF/lib/<Mysql_jar> to be taken BEFORE the common/lib/<Mysql_jar> one when it is possible
and
the common/lib/<Mysql_jar> to be taken in other cases.

So I tried to put 
<Loader className="org.apache.catalina.loader.WebappLoader" delegate="false" />
or 
<Loader className="org.apache.catalina.loader.WebappLoader" delegate="true" />
in my Context.xml
But it is always the common/lib/jar one which is taken :-((

I don't know if it is a bug or a bad config from me ....

If a Tomcat Developer can say to me what I am wrong ...

Note : To confirm the Driver version, I print :
dataSource.getClass().getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");

Cheers
On Sat, 19 Mar 2005 17:44:40 +1300
Simon Kitching <sk...@apache.org> wrote:

> Hi,
> 
> I see here that there is an option for the webapp-specific classloader
> to use parent-first classloading instead of the (default) child-first
> classloading.
> 
> Can someone suggest why this might be useful? Clearly someone thought
> so, but I can't see any point in it. It is in catalina since version 1.1
> (committer: Remy Maucherat).
> 
> See "delegate" option in this page:
>   http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/loader.html
> 
> Using this option makes life exceedingly complicated for some libs like
> commons-beanutils and commons-logging, so I would like to know under
> what conditions someone might enable this feature.
> 
> Regards,
> 
> Simon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

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


Re: use of Delegate ...

Posted by Lionel Farbos <li...@free.fr>.
On Sat, 26 Mar 2005 16:46:44 +0100
Simon Kitching <sk...@apache.org> wrote:

> I don_t understand; If you want jars from the war-specific WEB-INF/lib 
> to be used BEFORE the common/lib version, then the default classloading 
> order (child-first) is exactly what you want, isn_t it?
yes, in my example, it's exactly this.

> 
> It_s the other order I_m puzzled about: why someone would want 
> common/lib to come before WEB-INF/lib (parent-first).
> 
Sorry, I have no example for this use; 

Perhaps for better performances (when you know that classes are in the parent classloader) ...
or perhaps this feature is mandatory ?...

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


Re: bug with Delegate ?

Posted by Lionel Farbos <li...@free.fr>.
Hi Simon,

I wanted to use this flag because, in my $CATALINA_HOME/common/lib,
I have mysql-connector-java-2.0.14-bin.jar
but, 
in some wars, I have 
WEB-INF/lib/mysql-connector-java-3.0.15-ga-bin.jar
WEB-INF/lib/naming-factory-dbcp.jar
and in other wars, I don't have any Driver Mysql

So, I'd want the war_WEB-INF/lib/<Mysql_jar> to be taken BEFORE the common/lib/<Mysql_jar> one when it is possible
and
the common/lib/<Mysql_jar> to be taken in other cases.

So I tried to put 
<Loader className="org.apache.catalina.loader.WebappLoader" delegate="false" />
or 
<Loader className="org.apache.catalina.loader.WebappLoader" delegate="true" />
in my Context.xml
But it is always the common/lib/jar one which is taken :-((

I don't know if it is a bug or a bad config from me ....

If a Tomcat Developer can say to me what I am wrong ...

Note : To confirm the Driver version, I print :
dataSource.getClass().getClassLoader().getResource("org/gjt/mm/mysql/Driver.class");

Cheers
On Sat, 19 Mar 2005 17:44:40 +1300
Simon Kitching <sk...@apache.org> wrote:

> Hi,
> 
> I see here that there is an option for the webapp-specific classloader
> to use parent-first classloading instead of the (default) child-first
> classloading.
> 
> Can someone suggest why this might be useful? Clearly someone thought
> so, but I can't see any point in it. It is in catalina since version 1.1
> (committer: Remy Maucherat).
> 
> See "delegate" option in this page:
>   http://jakarta.apache.org/tomcat/tomcat-5.0-doc/config/loader.html
> 
> Using this option makes life exceedingly complicated for some libs like
> commons-beanutils and commons-logging, so I would like to know under
> what conditions someone might enable this feature.
> 
> Regards,
> 
> Simon
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 

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