URLClassLoader plugin system.... getting java.lang.NoClassDefFoundError

N

netpro2k

im working on a plugin system that reads an XML and loads classes from
jars. Each module is loaded via a new URLClassLoader with their url.
The XML also contains names for each module ... any module that wants
another module calls the static meathod in Hub getModuleInstance(name)
.... this returns a module (an interface)...

All was going well for awhile while i was working on it and trying it
via my IDE...I recently created an ant build script that makes jars
from everything... so now the module classes are only in the jars...
not the jars and the classpath as was the case when ran from my IDE...

The module loading and naming works properly for several modules...
but when loading one it fails with a java.lang.NoClassDefFoundError on
a module it is trying to use. This module is the only module so far
that relies on another module without an interface in the classpath
(it has it as a member variable)

details (module interface is in the classpath):

login implements module (login is loaded from a jar via a
URLClassLoader)

connectionDefImpl implements connection,module (connectionDefImpl is
loaded from a jar via URLClassLoader, connection is in the classpath)

nnDatabaseConn implements module, databaseConn (nnDatabaseConn is
loaded from jar via URLClassLoader, databaseConn is in the classpath)

guiModule implements module extends JFrame (guiModule is loaded from
jar via URLClassLoader)

nnOS implements mdoule, iconCallBack (nnOS is loaded from jar via
URLClassLoader, iconCallback is in classpath)
nnOS has a member variable of type guiModule that is set to a
reference of the instance gotten from Hub...

hub loads up reads its config file and creates URLClassLoaders for
each jar .. then gets the Class object for each (loading the class
marked as Main-Class: in the jar)... then starts login (staring means
instantiating it if not done yet and calling the start meathod on
it)... login then starts connection and connects... then guiModule is
started... guiModule starts and asks hub for an instance of nnOS...
nnOS trys to instantiate but fails with an error of:
java.lang.NoClassDefFoundError:
com/summationtech/symmetry/client/Modules/guiModule

i think it may be that i have a guiModule member variable in nnOS and
subsequently have to import it, and guiModule is not in the
classpath.. if this is the reason how can i create a field of this
type without having to import it, or have it in the classpath (it is
loaded from a URLClassLoader)
 
L

Lee Fesperman

netpro2k said:
im working on a plugin system that reads an XML and loads classes from
jars. Each module is loaded via a new URLClassLoader with their url.
The XML also contains names for each module ... any module that wants
another module calls the static meathod in Hub getModuleInstance(name)
... this returns a module (an interface)...

All was going well for awhile while i was working on it and trying it
via my IDE...I recently created an ant build script that makes jars
from everything... so now the module classes are only in the jars...
not the jars and the classpath as was the case when ran from my IDE...

...

guiModule implements module extends JFrame (guiModule is loaded from
jar via URLClassLoader)

nnOS implements mdoule, iconCallBack (nnOS is loaded from jar via
URLClassLoader, iconCallback is in classpath)
nnOS has a member variable of type guiModule that is set to a
reference of the instance gotten from Hub...

hub loads up reads its config file and creates URLClassLoaders for
each jar .. then gets the Class object for each (loading the class
marked as Main-Class: in the jar)... then starts login (staring means
instantiating it if not done yet and calling the start meathod on
it)... login then starts connection and connects... then guiModule is
started... guiModule starts and asks hub for an instance of nnOS...
nnOS trys to instantiate but fails with an error of:
java.lang.NoClassDefFoundError:
com/summationtech/symmetry/client/Modules/guiModule

i think it may be that i have a guiModule member variable in nnOS and
subsequently have to import it, and guiModule is not in the
classpath.. if this is the reason how can i create a field of this
type without having to import it, or have it in the classpath (it is
loaded from a URLClassLoader)

You weren't clear, but apparently nnOS and guiModule are in different jars, with
different classloaders. If so, you'll have to either:

1) Make a classloader that combines both jars,
2) Make the guiModule classloader the parent of the nnOS classloader,
3) Make a guiModule interface and put it on the classpath, or
4) Have nnOS get a reference to guiModule with getModuleInstance().

If 4), nnOS will only be able to use guiModule through the module interface.

For the general case, you'll probably need to make a single classloader for all
referenced jars.

BTW, you should follow Sun's conventions for naming --- package names should be all
lowercase and class and interface names should be capitalized.
 
N

netpro2k

Lee Fesperman said:
You weren't clear, but apparently nnOS and guiModule are in different jars, with
different classloaders. If so, you'll have to either:

1) Make a classloader that combines both jars,
2) Make the guiModule classloader the parent of the nnOS classloader,
3) Make a guiModule interface and put it on the classpath, or
4) Have nnOS get a reference to guiModule with getModuleInstance().

If 4), nnOS will only be able to use guiModule through the module interface.

For the general case, you'll probably need to make a single classloader for all
referenced jars.

BTW, you should follow Sun's conventions for naming --- package names should be all
lowercase and class and interface names should be capitalized.

Thanks for the response.... shortly after posting i tried making the
system classLoader the parent of all of the URLClassLoaders... this
didnt work, so i tried usiong a single class loader for all modules
(had to extend URLClassLoader for its protected addURL function) ...
this did work.... thanks anyway for the response
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top