Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   URLClassLoader plugin system.... getting java.lang.NoClassDefFoundError (http://www.velocityreviews.com/forums/t125853-urlclassloader-plugin-system-getting-java-lang-noclassdeffounderror.html)

netpro2k 08-20-2003 11:11 PM

URLClassLoader plugin system.... getting java.lang.NoClassDefFoundError
 
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)

Lee Fesperman 08-21-2003 02:24 AM

Re: URLClassLoader plugin system.... getting java.lang.NoClassDefFoundError
 
netpro2k wrote:
>
> 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.

--
Lee Fesperman, FirstSQL, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)

netpro2k 08-21-2003 03:12 PM

Re: URLClassLoader plugin system.... getting java.lang.NoClassDefFoundError
 
Lee Fesperman <firstsql@ix.netcom.com> wrote in message news:<3F442CD8.50A6@ix.netcom.com>...
> netpro2k wrote:
> >
> > 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.


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


All times are GMT. The time now is 02:24 AM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57