Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > URLClassLoader plugin system.... getting java.lang.NoClassDefFoundError

Reply
Thread Tools

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

 
 
netpro2k
Guest
Posts: n/a
 
      08-20-2003
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)
 
Reply With Quote
 
 
 
 
Lee Fesperman
Guest
Posts: n/a
 
      08-21-2003
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)
 
Reply With Quote
 
 
 
 
netpro2k
Guest
Posts: n/a
 
      08-21-2003
Lee Fesperman <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
URLClassloader loading class with unknown package name Cory Java 13 05-31-2011 08:31 PM
Getting reference of eclipse plugin view or its component from another eclipse plugin view? Jimmy Java 0 03-15-2007 11:04 PM
URLClassLoader and Tomcat Romain Java 2 09-29-2005 10:08 AM
URLClassLoader slow in 1.4.2 Timothy Fosdike Java 0 08-26-2004 02:08 AM
help.! Java URLClassloader Sundar Java 1 11-04-2003 04:02 PM



Advertisments