You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@avalon.apache.org by Serge Knystautas <se...@lokitech.com> on 2001/11/01 06:00:01 UTC

Re: Classloader thoughts?

Peter,

After trying (and failing) to get mailets loading from anything besides
james.bar, I read your message from Sept 30.  First, let me explain what I
want to do (in james), what I tried, and what happened:

Ideally james.sar could create an app/james/classes directory, that I would
probably populate with a sample mailet if necessary, and any class in this
classes directory would get loaded by the
org.apache.avalon.phoenix.components.classloader.PolicyClassLoader that
loads the bars in apps/james/blocks and jars in apps/james/lib.  Perhaps
this could get loaded by a classloader that has this PolicyClassLoader as a
parent so that the apps/james/classes classloader could be recycled so I
could reload mailet classes without needing to reload all the James classes.

If that's too ambitious for now, I would like to be able to add a jar to the
app/james/lib directory and have it load.  Unfortunately it seems the sar
remembers what jars it put in apps/james/lib, and if I put another jar in
there, avalon ignores it.

My last recourse was to put my jar in the core lib directory, which gets
loaded by sun.misc.Launcher$ExtClassLoader, because the run scripts now set
that lib folder as the ext folder.  Unfortunately mailets in there can't
access the mailet.jar, mail.jar, or activation.jar classes, so the server
just hangs (kind of weird... never throws any exception... I would if this
is a bug in the ExtClassLoader).

Mapping out a series of ClassLoaders might be useful, but as you mentioned,
I'm not sure how that would look in server.xml.  Do you need the extra
method to BlockContext to get the classloader since on object in that block
would return the same thing by calling getClass().getClassLoader(), or would
it return something different?

Serge Knystautas
Loki Technologies - Unstoppable Websites
http://www.lokitech.com/
----- Original Message -----
From: "Peter Donald" <do...@apache.org>
To: "Avalon Development" <av...@jakarta.apache.org>
Sent: Friday, October 26, 2001 7:09 AM
Subject: Re: Classloader thoughts?


> On Thu, 25 Oct 2001 05:35, Serge Knystautas wrote:
> > Again in JAMES... I've noticed some weird behavior I can't quite figure
out
> > (or figure out how to better figure out).  In a class that's loaded in
> > james.bar (in the apps/blocks directory that's extracted from
james.sar), I
> > call Class.forName(myClassName).newInstance().  However, it doesn't seem
to
> > want to load the class unless I have it in that james.bar file.  Is
there a
> > way I can load classes that are there OR in dist/apps/james/lib OR in
> > dist/lib?
>
> hmm - thats a bug - will look at it tomorrow.
>
> > Also, is there a way I can add a dist/classes directory (or
> > dist/apps/james/classes) and pull classes from there as well?
> >
> > (or point me towards where the classloader are for the bars/sars)
>
> The ClassLoader should be accessible from
>
> Thread.currentThread().getContextClassLoader()
>
> However we have also been talking about expanding ClassLoader
> support/management. I wouldn't mind hearing your opinion on a mail I wrote
on
> Sept 30 titled "[phoenix] RT: ClassLoader hierarchy".
>
> --
> Cheers,
>
> Pete
>
> ---------------------------------------------------
> "Wise men don't need advice. Fools don't take it."
>                         -Benjamin Franklin
> ---------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: avalon-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: avalon-dev-help@jakarta.apache.org
>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Classloader thoughts?

Posted by Serge Knystautas <se...@lokitech.com>.
Thanks Peter!  Assuming this works (and Paul's confirmed), this is perfect.
I'll even move some of the sample mailets/matchers into the classes
directory so ant moves them and mailet developers will more readily see some
sample code.  Thanks again.

Serge Knystautas
Loki Technologies - Unstoppable Websites
http://www.lokitech.com/
----- Original Message -----
From: "Peter Donald" <do...@apache.org>
To: "Avalon Developers List" <av...@jakarta.apache.org>
Sent: Tuesday, November 06, 2001 12:05 AM
Subject: Re: Classloader thoughts?


> On Thu, 1 Nov 2001 16:00, Serge Knystautas wrote:
> > Peter,
> >
> > After trying (and failing) to get mailets loading from anything besides
> > james.bar, I read your message from Sept 30.  First, let me explain what
I
> > want to do (in james), what I tried, and what happened:
>
> kool.
>
> > Ideally james.sar could create an app/james/classes directory, that I
would
> > probably populate with a sample mailet if necessary, and any class in
this
> > classes directory would get loaded by the
> > org.apache.avalon.phoenix.components.classloader.PolicyClassLoader that
> > loads the bars in apps/james/blocks and jars in apps/james/lib.  Perhaps
> > this could get loaded by a classloader that has this PolicyClassLoader
as a
> > parent so that the apps/james/classes classloader could be recycled so I
> > could reload mailet classes without needing to reload all the James
> > classes.
>
> In theory all the jars in blocks/ and lib/ directory should be loaded via
the
> same ClassLoader (However we experimented with a few things re ClassLoader
a
> bit back so that may have caused issues). So in theory you should be able
to
> do something like the following.
>
> BlockContext context = ...;
> File homeDir = context.getHomeDirectory();
> File classesDir = new File( homeDir, "classes" );
> URL[] urls = new URL[] { classesDir.toURL() };
>
> ClassLoader parent = James.class.getClassLoader();
>
> URLClassLoader classloader = URLClassLoader.newInstance( urls, parent );
>
> then in theory you should be able to load mailets/matchers out of this
> classloader. You should also be able to throw it away later and reload it
all
> providing that all matchers/mailets are in classes/ directory.
>
> > If that's too ambitious for now, I would like to be able to add a jar to
> > the app/james/lib directory and have it load.  Unfortunately it seems
the
> > sar remembers what jars it put in apps/james/lib, and if I put another
jar
> > in there, avalon ignores it.
>
> As it was then the .sar is only extracted the first time it is spotted. So
if
> you want ti to be extracted again it is necessary to delete the directory.
> Though I have been thinking about a few things related to this of late.
Stay
> tuned ;)
>
> > My last recourse was to put my jar in the core lib directory, which gets
> > loaded by sun.misc.Launcher$ExtClassLoader, because the run scripts now
set
> > that lib folder as the ext folder.  Unfortunately mailets in there can't
> > access the mailet.jar, mail.jar, or activation.jar classes, so the
server
> > just hangs (kind of weird... never throws any exception... I would if
this
> > is a bug in the ExtClassLoader).
>
> eek - no idea ;)
>
> > Mapping out a series of ClassLoaders might be useful, but as you
mentioned,
> > I'm not sure how that would look in server.xml.  Do you need the extra
> > method to BlockContext to get the classloader since on object in that
block
> > would return the same thing by calling getClass().getClassLoader(), or
> > would it return something different?
>
> well it could return something different - depending on which ClassLoader
you
> asked for. For instance in the other thread where I was discussin similar
> things with Paul you may want to
>
> ClassLoader classLoader = getClassLoader( "client-api" );
>
> which would get the class loader that only contained mailet.jar in it.
>
> --
> Cheers,
>
> Pete



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Classloader thoughts?

Posted by Paul Hammant <Pa...@yahoo.com>.
Serge,

>
>In theory all the jars in blocks/ and lib/ directory should be loaded via the 
>same ClassLoader (However we experimented with a few things re ClassLoader a 
>bit back so that may have caused issues). So in theory you should be able to 
>do something like the following. 
>
>BlockContext context = ...;
>File homeDir = context.getHomeDirectory();
>File classesDir = new File( homeDir, "classes" );
>URL[] urls = new URL[] { classesDir.toURL() };
>
>ClassLoader parent = James.class.getClassLoader();
>
>URLClassLoader classloader = URLClassLoader.newInstance( urls, parent );
>
>then in theory you should be able to load mailets/matchers out of this 
>classloader. You should also be able to throw it away later and reload it all 
>providing that all matchers/mailets are in classes/ directory.
>
I can vouch for this as it works for Jesktop like this.  It you are 
using Fede's Store then you'll have to be careful with the classloader 
there too.

- Paul


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Classloader thoughts?

Posted by Peter Donald <do...@apache.org>.
On Thu, 1 Nov 2001 16:00, Serge Knystautas wrote:
> Peter,
>
> After trying (and failing) to get mailets loading from anything besides
> james.bar, I read your message from Sept 30.  First, let me explain what I
> want to do (in james), what I tried, and what happened:

kool.

> Ideally james.sar could create an app/james/classes directory, that I would
> probably populate with a sample mailet if necessary, and any class in this
> classes directory would get loaded by the
> org.apache.avalon.phoenix.components.classloader.PolicyClassLoader that
> loads the bars in apps/james/blocks and jars in apps/james/lib.  Perhaps
> this could get loaded by a classloader that has this PolicyClassLoader as a
> parent so that the apps/james/classes classloader could be recycled so I
> could reload mailet classes without needing to reload all the James
> classes.

In theory all the jars in blocks/ and lib/ directory should be loaded via the 
same ClassLoader (However we experimented with a few things re ClassLoader a 
bit back so that may have caused issues). So in theory you should be able to 
do something like the following. 

BlockContext context = ...;
File homeDir = context.getHomeDirectory();
File classesDir = new File( homeDir, "classes" );
URL[] urls = new URL[] { classesDir.toURL() };

ClassLoader parent = James.class.getClassLoader();

URLClassLoader classloader = URLClassLoader.newInstance( urls, parent );

then in theory you should be able to load mailets/matchers out of this 
classloader. You should also be able to throw it away later and reload it all 
providing that all matchers/mailets are in classes/ directory.

> If that's too ambitious for now, I would like to be able to add a jar to
> the app/james/lib directory and have it load.  Unfortunately it seems the
> sar remembers what jars it put in apps/james/lib, and if I put another jar
> in there, avalon ignores it.

As it was then the .sar is only extracted the first time it is spotted. So if 
you want ti to be extracted again it is necessary to delete the directory. 
Though I have been thinking about a few things related to this of late. Stay 
tuned ;)

> My last recourse was to put my jar in the core lib directory, which gets
> loaded by sun.misc.Launcher$ExtClassLoader, because the run scripts now set
> that lib folder as the ext folder.  Unfortunately mailets in there can't
> access the mailet.jar, mail.jar, or activation.jar classes, so the server
> just hangs (kind of weird... never throws any exception... I would if this
> is a bug in the ExtClassLoader).

eek - no idea ;)

> Mapping out a series of ClassLoaders might be useful, but as you mentioned,
> I'm not sure how that would look in server.xml.  Do you need the extra
> method to BlockContext to get the classloader since on object in that block
> would return the same thing by calling getClass().getClassLoader(), or
> would it return something different?

well it could return something different - depending on which ClassLoader you 
asked for. For instance in the other thread where I was discussin similar 
things with Paul you may want to 

ClassLoader classLoader = getClassLoader( "client-api" );

which would get the class loader that only contained mailet.jar in it. 

-- 
Cheers,

Pete

*------------------------------------------------------*
| "Computers are useless. They can only give you       |
|            answers." - Pablo Picasso                 |
*------------------------------------------------------*

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>