-----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: [EMAIL PROTECTED]
| For additional commands, e-mail: [EMAIL PROTECTED]
|
|
|
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
iD8DBQFCSumeaCoPKRow/gARAlCCAKChFKex0Pq0c7FPMxAYqG6BQwB2igCgkjLc
KFj/+y27akECgiXNHB4A8n4=
=6c12
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]