You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Hamster <ha...@gmail.com> on 2007/06/12 16:42:59 UTC

global/separate classloader for each web-app

Hi,
In resin, there is a possibility to configure it with following:

    <web-app-default>
      <!--
          - Extension library for common jar files.  The ext is safe
          - even for non-classloader aware jars.  The loaded classes
          - will be loaded separately for each web-app, i.e. the class
          - itself will be distinct.
      -->
      <class-loader>
        <tree-loader path="${server.rootDirectory}/ext-webapp"/>
      </class-loader>

When above configuration is used then each jar placed in ext-webapp
directory is loaded for each web-app X1, X2, ... just like it would be
placed in X1/WEB-INF/lib, X2/WEB-INF/lib, ...

Our customer asked us if it is possible in Tomcat.

According to http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
it is not possible, could you please confirm or give me any tip or
idea (I know that it is not correct approach - but it is customer
request - cannot do much about it ;)).

Maybe there is a way to extend Tomcat, maybe there is already a
solution of this problem?

Thanks,
Hamster

-- 
GMail::Hamster
http://music-codex.com/
http://hamsterready.blogspot.com/

---------------------------------------------------------------------
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: global/separate classloader for each web-app

Posted by Hamster <ha...@gmail.com>.
On 12/06/07, Jon Wingfield <jo...@mkodo.com> wrote:
> You can supply a custom loader for a webapp to do this sort of thing:
> http://tomcat.apache.org/tomcat-5.5-doc/config/loader.html
> Each webapp would require a context.xml to enable the custom loader.
Thank you Jon for this tip, so according to
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html and:

"in the $CATALINA_HOME/conf/context.xml file: the Context element
information will be loaded by all webapps"

I can create my own loader (for example I can extend WebappLoader) and
configure it in context.xml file. I will try it ;]

Thanks,

Hamster,

-- 
GMail::Hamster
http://music-codex.com/
http://hamsterready.blogspot.com/

---------------------------------------------------------------------
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: global/separate classloader for each web-app

Posted by Jon Wingfield <jo...@mkodo.com>.
You can supply a custom loader for a webapp to do this sort of thing:
http://tomcat.apache.org/tomcat-5.5-doc/config/loader.html
Each webapp would require a context.xml to enable the custom loader.

Regards,

Jon

Hamster wrote:
> Hi,
> In resin, there is a possibility to configure it with following:
>
>    <web-app-default>
>      <!--
>          - Extension library for common jar files.  The ext is safe
>          - even for non-classloader aware jars.  The loaded classes
>          - will be loaded separately for each web-app, i.e. the class
>          - itself will be distinct.
>      -->
>      <class-loader>
>        <tree-loader path="${server.rootDirectory}/ext-webapp"/>
>      </class-loader>
>
> When above configuration is used then each jar placed in ext-webapp
> directory is loaded for each web-app X1, X2, ... just like it would be
> placed in X1/WEB-INF/lib, X2/WEB-INF/lib, ...
>
> Our customer asked us if it is possible in Tomcat.
>
> According to 
> http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
> it is not possible, could you please confirm or give me any tip or
> idea (I know that it is not correct approach - but it is customer
> request - cannot do much about it ;)).
>
> Maybe there is a way to extend Tomcat, maybe there is already a
> solution of this problem?
>
> Thanks,
> Hamster
>



---------------------------------------------------------------------
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: global/separate classloader for each web-app

Posted by Hamster <ha...@gmail.com>.
On 12/06/07, David Delbecq <de...@oma.be> wrote:
[..]
> Stupid suggestion:
Hehe, stupid approach requires stupid solutions ;]

> What about one of those approach
>
> 1) revise war build process to force inclusion of libs
>
> 2) have a server lifecyclelistener  that, before loading of a webapp,
> copy the concerned classes to the WEB-INF/lib ?
>
> Copy seems easier than play with classloader...
Thank you David for this suggestion it is worth to check and consider.

-- 
GMail::Hamster
http://music-codex.com/
http://hamsterready.blogspot.com/

---------------------------------------------------------------------
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: global/separate classloader for each web-app

Posted by Hamster <ha...@gmail.com>.
On 12/06/07, David Delbecq <de...@oma.be> wrote:
[..]
> 1) revise war build process to force inclusion of libs
>
> 2) have a server lifecyclelistener  that, before loading of a webapp,
> copy the concerned classes to the WEB-INF/lib ?
>
> Copy seems easier than play with classloader...

Here is my solution which I tested and it works pretty fine:
1/ in conf/context.xml I put:
    <Listener className="foo.FooListener" extDir="${catalina.home}/ext-lib/"/>

2/ I put my foo.FooListener in jar and then in ./server/lib/

3/ source code:

/** FIXME polish, add logging, exception handling, etc */
public class FooListener implements LifecycleListener {

  private String extDir;

  public String getExtDir() {
    return extDir;
  }

  public void lifecycleEvent(LifecycleEvent event) {
    if (Lifecycle.START_EVENT.equals(event.getType())) {
      if (event.getSource() != null) {
        final StandardContext ctx = (StandardContext) event.getSource();
        final File dir = new File(getExtDir());
        File[] files = dir.listFiles();
        for (int i = 0; i < files.length; i++) {
          ctx.getLoader().addRepository("file://" + files[i].getAbsolutePath());
        }
      }
    }
  }

  /**
   * Required configuration parameter.
   *
   * @param extDir
   */
  public void setExtDir(String extDir) {
    this.extDir = extDir;
  }

}

That's all, it works fine, it does not affect classloader hierarchy
and it is logically equal to copy-based solution.

Thanks for your help, now let's wait what customer say ;)

Hamster,

-- 
GMail::Hamster
http://music-codex.com/
http://hamsterready.blogspot.com/

---------------------------------------------------------------------
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: global/separate classloader for each web-app

Posted by David Delbecq <de...@oma.be>.
Hamster a écrit :
> On 12/06/07, David Delbecq <de...@oma.be> wrote:
>> What's the point? Saving 2 Megs of hard disk space and, at the same
>> time, risk to break deployed apps that sudeently get additionnal libs
>> that can conflit in version with vendor supplied one?
>
> Don't ask me!
> It is their request, they said something about security concerns,
> fast security related libraries updated, etc... eh, do not ask ;(
>
> BTW I tried to use my own Loader in conf/context.xml it throws
> exceptions... I will keep working ;]
>
> Oh, and here is why it is important for me:
> If I will not be able to do that then they are going to put everything
> in commons/lib and all applications will use same version of libraries
> in shared classloader ;( and that is going to break all the apps ;]
> and someone will have to "fix" or "upgrade" them to "the new
> approach", and it's going to be me, not funny at all.
>
>
> Hamster,
>
Stupid suggestion:
What about one of those approach

1) revise war build process to force inclusion of libs

2) have a server lifecyclelistener  that, before loading of a webapp,
copy the concerned classes to the WEB-INF/lib ?

Copy seems easier than play with classloader...

---------------------------------------------------------------------
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: global/separate classloader for each web-app

Posted by Hamster <ha...@gmail.com>.
On 12/06/07, David Delbecq <de...@oma.be> wrote:
> What's the point? Saving 2 Megs of hard disk space and, at the same
> time, risk to break deployed apps that sudeently get additionnal libs
> that can conflit in version with vendor supplied one?

Don't ask me!
It is their request, they said something about security concerns,
fast security related libraries updated, etc... eh, do not ask ;(

BTW I tried to use my own Loader in conf/context.xml it throws
exceptions... I will keep working ;]

Oh, and here is why it is important for me:
If I will not be able to do that then they are going to put everything
in commons/lib and all applications will use same version of libraries
in shared classloader ;( and that is going to break all the apps ;]
and someone will have to "fix" or "upgrade" them to "the new
approach", and it's going to be me, not funny at all.


Hamster,

-- 
GMail::Hamster
http://music-codex.com/
http://hamsterready.blogspot.com/

---------------------------------------------------------------------
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: global/separate classloader for each web-app

Posted by David Delbecq <de...@oma.be>.
What's the point? Saving 2 Megs of hard disk space and, at the same
time, risk to break deployed apps that sudeently get additionnal libs
that can conflit in version with vendor supplied one?
Hamster a écrit :
> Hi,
> In resin, there is a possibility to configure it with following:
>
>    <web-app-default>
>      <!--
>          - Extension library for common jar files.  The ext is safe
>          - even for non-classloader aware jars.  The loaded classes
>          - will be loaded separately for each web-app, i.e. the class
>          - itself will be distinct.
>      -->
>      <class-loader>
>        <tree-loader path="${server.rootDirectory}/ext-webapp"/>
>      </class-loader>
>
> When above configuration is used then each jar placed in ext-webapp
> directory is loaded for each web-app X1, X2, ... just like it would be
> placed in X1/WEB-INF/lib, X2/WEB-INF/lib, ...
>
> Our customer asked us if it is possible in Tomcat.
>
> According to
> http://tomcat.apache.org/tomcat-5.5-doc/class-loader-howto.html
> it is not possible, could you please confirm or give me any tip or
> idea (I know that it is not correct approach - but it is customer
> request - cannot do much about it ;)).
>
> Maybe there is a way to extend Tomcat, maybe there is already a
> solution of this problem?
>
> Thanks,
> Hamster
>

---------------------------------------------------------------------
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