hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Liebig, Stefan " <Stefan.Lie...@compeople.de>
Subject AW: [ON TOPIC]Any pointers on how to make a custom classloader?
Date Thu, 31 Mar 2005 05:36:58 GMT
Have a look at http://forum.java.sun.com/thread.jspa?forumID=32&messageID=2629602&threadID=300557
This also might help you.
 
Stefan

________________________________

Von: Geoff Longman [mailto:glongman@gmail.com]
Gesendet: Mi 30.03.2005 20:55
An: hivemind-user@jakarta.apache.org
Betreff: Re: [ON TOPIC]Any pointers on how to make a custom classloader?



Cool, I've used your example as a model. Actually I think it's simpler
for me, I just need to find the correct URLs from the project, create
the URLClassloader and pass it to the HM DefaultClassResolver
constructor (I hope)

We'll see.

thx all

Geoff


On Wed, 30 Mar 2005 12:02:06 -0600, Brian K. Wallace
<brian@transmorphix.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> One place to look if you're so inclined is at Ant's Launcher
> (org.apache.tools.ant.launch.Launcher). I used that as a basis for
> creating a custom classloader and executing subsets of code in entirely
> different environments. The meat (after setting up the classpath fro the
> ~ URLClassLoader) simply involves loading the class from the classloader
> instead of calling newInstance in the current thread.
>
> <summary snippet>
> ~    // Except for 'Locator' calls, this functionality is from Launcher.
> Locator is also a part of Ant
> ~    URL[] jars = Locator.getLocationURLs(contextRunPath);
> ~    URLClassLoader loader = new URLClassLoader(jars, Thread.currentThread()
> ~        .getContextClassLoader().getParent());
> ~    Thread.currentThread().setContextClassLoader(loader);
> ~    Class mainClass = null;
> ~    Runnable main = null;
> ~    try {
> ~      mainClass = loader.loadClass(MAIN_CLASS); // Main class is passed
> in on the command line
> ~      main = (Runnable) mainClass.newInstance();
> ~    } catch (ClassNotFoundException cnfe) {
> ~      throw new LaunchException("Unable to find main class [" + MAIN_CLASS
> ~          + "]");
> ~    } catch (InstantiationException ie) {
> ~      throw new LaunchException("Unable to instantiate main class ["
> ~          + MAIN_CLASS + "]");
> ~    } catch (IllegalAccessException iae) {
> ~      throw new LaunchException("Illegal access to main class [" +
> MAIN_CLASS
> ~          + "]");
> ~    }
> ~    main.run();
> </summary snippet>
>
> HTH
>
> Geoff Longman wrote:
> | I'm whipping up a demo Eclipse plugin that will create a Registry
> | based on the classpath of a Java project. The plugin will contain a
> | view that will display the contents of the Registry.
> |
> | I need a classloader that I can add the project jars and output folder
> | to in order to create a ClassResolver.
> |
> | But, I have never played with custom classloaders so if anyone has a
> | pointer to a good resource explaining how to make one I'd be grateful!
> |
> | This work is to improve my understanding of how HM works inside so I
> | can better approach Spindle -> Tapestry 3.1
> |
> | Geoff
> |
> | ---------------------------------------------------------------------
> | To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> | For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
> |
> |
> |
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.5 (MingW32)
>
> iD8DBQFCSumeaCoPKRow/gARAlCCAKChFKex0Pq0c7FPMxAYqG6BQwB2igCgkjLc
> KFj/+y27akECgiXNHB4A8n4=
> =6c12
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: hivemind-user-help@jakarta.apache.org
>
>

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




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


Mime
View raw message