Hi

> What's "Utils" and "classpath"?

A utility class and a member String in my system. These work.

> Can't you just call super.findClass(className)?

No.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ClassLoader.html#findClass
(java.lang.String)
Finds the specified class. This method should be overridden by class loader
implementations that follow the delegation model for loading classes, and
will be invoked by the loadClass method after checking the parent class
loader for the requested class. The default implementation throws a
ClassNotFoundException. 

So which ClassLoader should I inherit from? java.lang.ClassLoader would
obviously not do it...


Thanks anyway,

Steffen




Just a guess:).

-----Original Message-----
From: SH Solutions [mailto:[EMAIL PROTECTED]
Sent: Friday, February 27, 2004 2:16 AM
To: [EMAIL PROTECTED]
Subject: Good practice for classloaders


Hi

I am writing an application in which I use classloaders to load different
groups of plugins.
Basically what I am doing is:

  protected Class findClass( String className )
    throws ClassNotFoundException
  {
    if ( className.startsWith( "com.companyname." ) )
      return getClass().getClassLoader().loadClass( className );
    byte classData[] = getTypeFromBasePath( className );
    if ( classData == null )
      throw new ClassNotFoundException();
    return defineClass( className, classData, 0, classData.length );
  }

  private byte[] getTypeFromBasePath( String typeName )
  {
    return Utils.readFile( classPath + typeName.replace( '.',
File.separatorChar ) + ".class" );
  }


Now, I have problems an obvious problem with jar-files. [I have already
posted this before.]
[Actually I do not understand this problem, since it worked well with
tomcat4.0.6, but thats another problem. Still any hints are wellcome...]

What I would like to do is get rid of the getTypeFromBasePath-method. I
would prefer to let the parent classloader do this part and only do the
defineClass myself.

What I am doing right now seems to be bad practice event to me. But what
would be good practice?
The once thing I want to archive is that I want to load these classes with
different classloaders to be able to reload them during the lifetime of my
application.

Can anyone give me any hint?

Thanks,
  Steffen


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to