JPython newbie, CLASSPATH question
RICKHIGH
rickhigh at aol.com
Tue Jan 4 05:01:49 EST 2000
No. But you can use the URLClassLoader to load the class. URLClassLoader is in
java.net. You can add a directory as a file URL.
Here is an excerpt that uses URLClassLoader:
...
from java.lang import ClassLoader, Exception
...
class AppletBrowser(JFrame, AppletContext, AppletStub):
...
...
def createClassLoader(self):
try:
# Get a list of URLS for each jar in the
archive tag.
# Get the codebase URL, and it to the list of
URLS.
# Create a URL jarray to pass to the
URLClassLoader constructor.
# Get the system class loader to pass to the
URLClassLoader constructor.
# Create an instance of URLClassLoader passing
the urls and
# the system class loader.
urls = self.getJars()
codebase=self.getCodeBase()
urls.append(codebase)
urls = array(urls, URL)
loader = ClassLoader.getSystemClassLoader()
url_loader = URLClassLoader(urls, loader)
if debug: print "Created class loader with " + `urls`
return url_loader
except Exception, exception:
global error
error = exception
print "Unable to create class loader"
def loadApplet(self):
#Create the class loader and get the class name.
class_loader=self.createClassLoader()
class_name = self.props.getProperty("code")
# Load the class, create an instance of it, and add it
with addApplet.
if class_name and class_loader:
try:
if debug: print "Loading the class: " +
class_name
clazz=class_loader.loadClass(class_name)
if debug: print clazz
applet = clazz.newInstance()
self.addApplet(applet)
except Exception, exception:
global error
error = exception
print "Unable to load the class " + class_name
...
...
The above is taken from an Applet container that allows an Applet to run as an
application. (Even on a different box.)
It uses URLClassLoader.
If you want to see more, i.e., if you want me to send the rest-- let me know.
There is a book coming on in March on JPython from publisher Addison Wesley.
You should check it out.
--Rick Hightower
More information about the Python-list
mailing list