Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Class Object From .class File



James,

Subclass ClassLoader into something like FileClassLoader. You would have
to override findClass to locate the class file, and also loadClassData to
read in the data once you have found it: The snippet below is modified
from a snippet in the javadoc for ClassLoader.


// appropriate imports go here.

public class FileClassLoader extends ClassLoader
{
// constructor would go here. probably call super();

public Class findClass(String name)
{
byte[] b = loadClassData(name); // you will define
loadClassData.
return defineClass(name,b,0,b.length); // defineClass is
given to you by ClassLoader.
}

private byte[] loadClassData(String name)
{
// you get to decide how to get from the name of the class
to its physical
// location. find the right file, read it in to a byte
array and return that.
}
}


Gary Dusbabek.







James Gray <email@hidden>
Sent by: email@hidden
05/31/2001 02:48 PM


To: email@hidden
cc:
Subject: Class Object From .class File


I've run into a little problem and could use a little help. My program
needs to dynamically load a few classes from files in a certain
directory. I know how to get and parse a list of those files and I also
know how how to verify and create instances from a Class object. The
knowledge I'm missing is the middle part. How do I go get the VM to
load a Class object from a File object? Thanks very much for your help.

James Gray

Plans are good. People are the problems. -Chris Keuchel
_______________________________________________
java-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/java-dev




Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.