tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yansheng Lin" <yansheng....@silvacom.com>
Subject RE: Good practice for classloaders
Date Fri, 27 Feb 2004 20:34:10 GMT
What's "Utils" and "classpath"?  Can't you just call super.findClass(className)?
Just a guess:).

-----Original Message-----
From: SH Solutions [mailto:sh-solutions@gmx.net] 
Sent: Friday, February 27, 2004 2:16 AM
To: tomcat-user@jakarta.apache.org
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: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message