You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Geoff Longman <gl...@intelligentworks.com> on 2004/03/10 07:37:55 UTC

[Hivemind] Question about customized ClassResolvers

Hey, I have tweaked up my own version of HiveMindFilter's init() method
because I want to run a junit test in Eclipse and have the Registry pick up
my as yet notjarred hivemodule.xml

Having looked at TestRegistryBuilder, it appears that this should work:

// want to pick up META-INF/hivemodule.xml in the project root
File f = new File("");
URL[] urls = new URL[] { f.toURL()};
ClassLoader loader =
    new URLClassLoader(urls,
Thread.currentThread().getContextClassLoader());
ClassResolver resolver = new DefaultClassResolver(loader);
// end of Tweak
RegistryBuilder builder = new RegistryBuilder();
builder.processModules(resolver);
_registry = builder.constructRegistry(getRegistryLocale());

When checking the URL from the File in the debugger it looks right, i.e. the
URL refers to the root of my project.

But, I get the following error:

org.apache.hivemind.ApplicationRuntimeException: Registry does not contain
module 'com.iw.session.local'.
 ^^^ the name of the module I have constructed.

Even stranger, if I leave the code above as is and force the Eclipse junit
test launch config classpath to contain the project root folder, everything
works - green lights across the board..

I'm not really that up on these classloader tricks. Does anyone see
something here?

Geoff

Geoffrey Longman
Intelligent Works Inc.


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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Geoff Longman <gl...@intelligentworks.com>.

> I don't know why you get this exceptions, but why don't you just put your
> module-descriptor in src/META-INF/hivemodule.xml. And than call
> Registry reg = RegistryBuilder.constructDefaultRegistry(). This will take
> all the META-INF/hivemodule.xml which are on the classpath - wheter jared
> or not.

Yes, I could do that. I was just trying to do it the "Howard" way.

>
> Apart of this my JUnit tests generally extend from
> org.apache.hivemind.test.HiveMindTestCase. It has a number of convienience
> methods one of which is buildFrameworkRegistry(), which also loads like
> above the hivemodules in META-INF, but for which you can additional
> specify module-descriptors which are located anywhere in the class-path.

Neat! And also the "Howard" way.

>
> Hopefully this helps a bit.
>
> Chris
>
>
> On Wed, 10 Mar 2004 01:37:55 -0500, Geoff Longman
> <gl...@intelligentworks.com> wrote:
>
> > Hey, I have tweaked up my own version of HiveMindFilter's init() method
> > because I want to run a junit test in Eclipse and have the Registry pick
> > up
> > my as yet notjarred hivemodule.xml
> >
> > Having looked at TestRegistryBuilder, it appears that this should work:
> >
> > // want to pick up META-INF/hivemodule.xml in the project root
> > File f = new File("");
> > URL[] urls = new URL[] { f.toURL()};
> > ClassLoader loader =
> >     new URLClassLoader(urls,
> > Thread.currentThread().getContextClassLoader());
> > ClassResolver resolver = new DefaultClassResolver(loader);
> > // end of Tweak
> > RegistryBuilder builder = new RegistryBuilder();
> > builder.processModules(resolver);
> > _registry = builder.constructRegistry(getRegistryLocale());
> >
> > When checking the URL from the File in the debugger it looks right, i.e.
> > the
> > URL refers to the root of my project.
> >
> > But, I get the following error:
> >
> > org.apache.hivemind.ApplicationRuntimeException: Registry does not
> > contain
> > module 'com.iw.session.local'.
> >  ^^^ the name of the module I have constructed.
> >
> > Even stranger, if I leave the code above as is and force the Eclipse
> > junit
> > test launch config classpath to contain the project root folder,
> > everything
> > works - green lights across the board..
> >
> > I'm not really that up on these classloader tricks. Does anyone see
> > something here?
> >
> > Geoff
> >
> > Geoffrey Longman
> > Intelligent Works Inc.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
>
>
> --
> Christian Essl
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Christian Essl <ch...@yahoo.de>.
I don't know why you get this exceptions, but why don't you just put your 
module-descriptor in src/META-INF/hivemodule.xml. And than call
Registry reg = RegistryBuilder.constructDefaultRegistry(). This will take 
all the META-INF/hivemodule.xml which are on the classpath - wheter jared 
or not.

Apart of this my JUnit tests generally extend from 
org.apache.hivemind.test.HiveMindTestCase. It has a number of convienience 
methods one of which is buildFrameworkRegistry(), which also loads like 
above the hivemodules in META-INF, but for which you can additional 
specify module-descriptors which are located anywhere in the class-path.

Hopefully this helps a bit.

Chris


On Wed, 10 Mar 2004 01:37:55 -0500, Geoff Longman 
<gl...@intelligentworks.com> wrote:

> Hey, I have tweaked up my own version of HiveMindFilter's init() method
> because I want to run a junit test in Eclipse and have the Registry pick 
> up
> my as yet notjarred hivemodule.xml
>
> Having looked at TestRegistryBuilder, it appears that this should work:
>
> // want to pick up META-INF/hivemodule.xml in the project root
> File f = new File("");
> URL[] urls = new URL[] { f.toURL()};
> ClassLoader loader =
>     new URLClassLoader(urls,
> Thread.currentThread().getContextClassLoader());
> ClassResolver resolver = new DefaultClassResolver(loader);
> // end of Tweak
> RegistryBuilder builder = new RegistryBuilder();
> builder.processModules(resolver);
> _registry = builder.constructRegistry(getRegistryLocale());
>
> When checking the URL from the File in the debugger it looks right, i.e. 
> the
> URL refers to the root of my project.
>
> But, I get the following error:
>
> org.apache.hivemind.ApplicationRuntimeException: Registry does not 
> contain
> module 'com.iw.session.local'.
>  ^^^ the name of the module I have constructed.
>
> Even stranger, if I leave the code above as is and force the Eclipse 
> junit
> test launch config classpath to contain the project root folder, 
> everything
> works - green lights across the board..
>
> I'm not really that up on these classloader tricks. Does anyone see
> something here?
>
> Geoff
>
> Geoffrey Longman
> Intelligent Works Inc.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org



-- 
Christian Essl 

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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Geoff Longman <gl...@intelligentworks.com>.
Ah yes, another alternative. It's pretty cool that HM is flexible enough to
allow these!

Geoff
----- Original Message -----
From: "Achim Huegen" <ah...@gmx-topmail.de>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Wednesday, March 10, 2004 5:04 AM
Subject: Re: [Hivemind] Question about customized ClassResolvers


> Hi,
>
> you could try to put the file in a source folder, so eclipse will output
> it to the classpath.
> Then you can build the registry like this:
>
> ClassResolver resolver = new DefaultClassResolver();
> RegistryBuilder builder = new RegistryBuilder();
> builder.processModules( resolver );
> URL moduleURL = resolver.getResource( "org/foo/hivemodule.xml" );
> builder.processModule(resolver, new URLResource( moduleURL ) );
> _registry = builder.constructRegistry(Locale.getDefault());
>
> Of course you must change the script, that builds the jar.
>
> Bye
>   Achim
>
>
> Am Wed, 10 Mar 2004 01:37:55 -0500 schrieb Geoff Longman
> <gl...@intelligentworks.com>:
>
> > Hey, I have tweaked up my own version of HiveMindFilter's init() method
> > because I want to run a junit test in Eclipse and have the Registry pick
> > up
> > my as yet notjarred hivemodule.xml
> >
> > Having looked at TestRegistryBuilder, it appears that this should work:
> >
> > // want to pick up META-INF/hivemodule.xml in the project root
> > File f = new File("");
> > URL[] urls = new URL[] { f.toURL()};
> > ClassLoader loader =
> >     new URLClassLoader(urls,
> > Thread.currentThread().getContextClassLoader());
> > ClassResolver resolver = new DefaultClassResolver(loader);
> > // end of Tweak
> > RegistryBuilder builder = new RegistryBuilder();
> > builder.processModules(resolver);
> > _registry = builder.constructRegistry(getRegistryLocale());
> >
> > When checking the URL from the File in the debugger it looks right, i.e.
> > the
> > URL refers to the root of my project.
> >
> > But, I get the following error:
> >
> > org.apache.hivemind.ApplicationRuntimeException: Registry does not
> > contain
> > module 'com.iw.session.local'.
> >  ^^^ the name of the module I have constructed.
> >
> > Even stranger, if I leave the code above as is and force the Eclipse
> > junit
> > test launch config classpath to contain the project root folder,
> > everything
> > works - green lights across the board..
> >
> > I'm not really that up on these classloader tricks. Does anyone see
> > something here?
> >
> > Geoff
> >
> > Geoffrey Longman
> > Intelligent Works Inc.
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Achim Huegen <ah...@gmx-topmail.de>.
Hi,

you could try to put the file in a source folder, so eclipse will output 
it to the classpath.
Then you can build the registry like this:

	ClassResolver resolver = new DefaultClassResolver();
	RegistryBuilder builder = new RegistryBuilder();
	builder.processModules( resolver );
	URL moduleURL = resolver.getResource( "org/foo/hivemodule.xml" );
	builder.processModule(resolver, new URLResource( moduleURL ) );
	_registry = builder.constructRegistry(Locale.getDefault());

Of course you must change the script, that builds the jar.

Bye
  Achim


Am Wed, 10 Mar 2004 01:37:55 -0500 schrieb Geoff Longman 
<gl...@intelligentworks.com>:

> Hey, I have tweaked up my own version of HiveMindFilter's init() method
> because I want to run a junit test in Eclipse and have the Registry pick 
> up
> my as yet notjarred hivemodule.xml
>
> Having looked at TestRegistryBuilder, it appears that this should work:
>
> // want to pick up META-INF/hivemodule.xml in the project root
> File f = new File("");
> URL[] urls = new URL[] { f.toURL()};
> ClassLoader loader =
>     new URLClassLoader(urls,
> Thread.currentThread().getContextClassLoader());
> ClassResolver resolver = new DefaultClassResolver(loader);
> // end of Tweak
> RegistryBuilder builder = new RegistryBuilder();
> builder.processModules(resolver);
> _registry = builder.constructRegistry(getRegistryLocale());
>
> When checking the URL from the File in the debugger it looks right, i.e. 
> the
> URL refers to the root of my project.
>
> But, I get the following error:
>
> org.apache.hivemind.ApplicationRuntimeException: Registry does not 
> contain
> module 'com.iw.session.local'.
>  ^^^ the name of the module I have constructed.
>
> Even stranger, if I leave the code above as is and force the Eclipse 
> junit
> test launch config classpath to contain the project root folder, 
> everything
> works - green lights across the board..
>
> I'm not really that up on these classloader tricks. Does anyone see
> something here?
>
> Geoff
>
> Geoffrey Longman
> Intelligent Works Inc.
>

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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Christian Essl <ch...@yahoo.de>.
Hi John,

I like your multimodule classloader. I think HiveMind needs something like 
that.

I was just wondering wheter the properties file is needed. I thought 
wheter it was possible to load all META-INF/hivemodule.xml and than parse 
the loaded ModuleDescriptors for contributions to a 'magic' config-point - 
ie 'hivemind.load-additional'. The contributions specify which additinal 
modules should be loaded.

I think this would not only save you an extra file but could also give 
runtime reflection about which modules are loaded from where.

Thanks,
Chris

On Wed, 10 Mar 2004 04:34:05 -0500 (EST), John Rubier 
<in...@insurgent.us> wrote:

> Hey Geoff,
> It may have something to do with HiveMind passing the path (hard coded) 
> "META-INF/hivemodule.xml". I think depending on how your project is set 
> up and/or what classloaders are involved, it may want /META-INF or who 
> knows. Just a guess.
> You might give that multimodule classloader I posted a few days back a 
> try as you can specify paths to the hivemodule.xml files in a properties 
> file. Now whether it will pick up the props file itself is a different 
> story :)
> I also haven't tried it under jetty/whatever...YMMV
>
> Take care,
>
> John
>
> On Wednesday March 10th 2004, Geoff Longman wrote:
>
>> Hey, I have tweaked up my own version of HiveMindFilter's init() method
>> because I want to run a junit test in Eclipse and have the Registry 
>> pick up
>> my as yet notjarred hivemodule.xml
>> Having looked at TestRegistryBuilder, it appears that this should work:
>> // want to pick up META-INF/hivemodule.xml in the project root
>> File f = new File("");
>> URL[] urls = new URL[] { f.toURL()};
>> ClassLoader loader =
>> new URLClassLoader(urls,
>> Thread.currentThread().getContextClassLoader());
>> ClassResolver resolver = new DefaultClassResolver(loader);
>> // end of Tweak
>> RegistryBuilder builder = new RegistryBuilder();
>> builder.processModules(resolver);
>> _registry = builder.constructRegistry(getRegistryLocale());
>> When checking the URL from the File in the debugger it looks right, 
>> i.e. the
>> URL refers to the root of my project.
>> But, I get the following error:
>> org.apache.hivemind.ApplicationRuntimeException: Registry does not 
>> contain
>> module 'com.iw.session.local'.
>> ^^^ the name of the module I have constructed.
>> Even stranger, if I leave the code above as is and force the Eclipse 
>> junit
>> test launch config classpath to contain the project root folder, 
>> everything
>> works - green lights across the board..
>> I'm not really that up on these classloader tricks. Does anyone see
>> something here?
>> Geoff
>> Geoffrey Longman
>> Intelligent Works Inc.
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org



-- 
Christian Essl 

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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Geoff Longman <gl...@intelligentworks.com>.
That fixed it. Thanks!

Geoff
----- Original Message -----
From: "Achim Huegen" <ah...@gmx-topmail.de>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Wednesday, March 10, 2004 9:44 AM
Subject: Re: [Hivemind] Question about customized ClassResolvers


> > BTW - The paths that are passed as URLs to URLClassloader:
> >
> > My Code:
> > file:/X:/eclipse/e21/workspace/hivemind-session-local
> >
> > TestRegistryBuilder:
> >
file:/X:/eclipse/e21/workspace/hivemind/src/test-data/TestRegistryBuilder
> >
>
> In the javadoc of URLClassloader is mentioned, that the url must end
> with a slash to be recognized as directory. Maybe this could be the
reason?
>
> Achim
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Achim Huegen <ah...@gmx-topmail.de>.
> BTW - The paths that are passed as URLs to URLClassloader:
>
> My Code:
> file:/X:/eclipse/e21/workspace/hivemind-session-local
>
> TestRegistryBuilder:
> file:/X:/eclipse/e21/workspace/hivemind/src/test-data/TestRegistryBuilder
>

In the javadoc of URLClassloader is mentioned, that the url must end
with a slash to be recognized as directory. Maybe this could be the reason?

Achim

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


Re: [Hivemind] Question about customized ClassResolvers

Posted by Geoff Longman <gl...@intelligentworks.com>.
I'll give your classloader a try at some point. For now, the hard coded
classpath in the Eclipse launch config works fine.

BTW - The paths that are passed as URLs to URLClassloader:

My Code:
file:/X:/eclipse/e21/workspace/hivemind-session-local

TestRegistryBuilder:
file:/X:/eclipse/e21/workspace/hivemind/src/test-data/TestRegistryBuilder

Funny, now TestRegistryBuilder fails with the same error. I think I stayed
up too late!

Geoff


----- Original Message -----
From: "John Rubier" <in...@insurgent.us>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Wednesday, March 10, 2004 4:34 AM
Subject: Re: [Hivemind] Question about customized ClassResolvers


> Hey Geoff,
> It may have something to do with HiveMind passing the path (hard coded)
"META-INF/hivemodule.xml". I think depending on how your project is set up
and/or what classloaders are involved, it may want /META-INF or who knows.
Just a guess.
> You might give that multimodule classloader I posted a few days back a try
as you can specify paths to the hivemodule.xml files in a properties file.
Now whether it will pick up the props file itself is a different story :)
> I also haven't tried it under jetty/whatever...YMMV
>
> Take care,
>
> John
>
> On Wednesday March 10th 2004, Geoff Longman wrote:
>
> > Hey, I have tweaked up my own version of HiveMindFilter's init() method
> > because I want to run a junit test in Eclipse and have the Registry pick
up
> > my as yet notjarred hivemodule.xml
> > Having looked at TestRegistryBuilder, it appears that this should work:
> > // want to pick up META-INF/hivemodule.xml in the project root
> > File f = new File("");
> > URL[] urls = new URL[] { f.toURL()};
> > ClassLoader loader =
> > new URLClassLoader(urls,
> > Thread.currentThread().getContextClassLoader());
> > ClassResolver resolver = new DefaultClassResolver(loader);
> > // end of Tweak
> > RegistryBuilder builder = new RegistryBuilder();
> > builder.processModules(resolver);
> > _registry = builder.constructRegistry(getRegistryLocale());
> > When checking the URL from the File in the debugger it looks right, i.e.
the
> > URL refers to the root of my project.
> > But, I get the following error:
> > org.apache.hivemind.ApplicationRuntimeException: Registry does not
contain
> > module 'com.iw.session.local'.
> > ^^^ the name of the module I have constructed.
> > Even stranger, if I leave the code above as is and force the Eclipse
junit
> > test launch config classpath to contain the project root folder,
everything
> > works - green lights across the board..
> > I'm not really that up on these classloader tricks. Does anyone see
> > something here?
> > Geoff
> > Geoffrey Longman
> > Intelligent Works Inc.
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


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


Re: [Hivemind] Question about customized ClassResolvers

Posted by John Rubier <in...@insurgent.us>.
Hey Geoff,
It may have something to do with HiveMind passing the path (hard coded) "META-INF/hivemodule.xml". I think depending on how your project is set up and/or what classloaders are involved, it may want /META-INF or who knows. Just a guess.
You might give that multimodule classloader I posted a few days back a try as you can specify paths to the hivemodule.xml files in a properties file. Now whether it will pick up the props file itself is a different story :)
I also haven't tried it under jetty/whatever...YMMV

Take care,

John

On Wednesday March 10th 2004, Geoff Longman wrote:

> Hey, I have tweaked up my own version of HiveMindFilter's init() method
> because I want to run a junit test in Eclipse and have the Registry pick up
> my as yet notjarred hivemodule.xml
> Having looked at TestRegistryBuilder, it appears that this should work:
> // want to pick up META-INF/hivemodule.xml in the project root
> File f = new File("");
> URL[] urls = new URL[] { f.toURL()};
> ClassLoader loader =
> new URLClassLoader(urls,
> Thread.currentThread().getContextClassLoader());
> ClassResolver resolver = new DefaultClassResolver(loader);
> // end of Tweak
> RegistryBuilder builder = new RegistryBuilder();
> builder.processModules(resolver);
> _registry = builder.constructRegistry(getRegistryLocale());
> When checking the URL from the File in the debugger it looks right, i.e. the
> URL refers to the root of my project.
> But, I get the following error:
> org.apache.hivemind.ApplicationRuntimeException: Registry does not contain
> module 'com.iw.session.local'.
> ^^^ the name of the module I have constructed.
> Even stranger, if I leave the code above as is and force the Eclipse junit
> test launch config classpath to contain the project root folder, everything
> works - green lights across the board..
> I'm not really that up on these classloader tricks. Does anyone see
> something here?
> Geoff
> Geoffrey Longman
> Intelligent Works Inc.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org

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