[Zope] Java class doesn't load correctly under windows
Josef Meile
jmeile at hotmail.com
Mon Aug 23 07:03:56 EDT 2004
Hi,
I'm trying to programatically load a java class file to a folder on the
Zope DB called 'JMFiles' during the initialization of a Product called
JMColorPicker. It works under linux, but on windows 2000 the applet
isn't showed and I got an error on the java console which says:
Error loading class: ColorPicker
java.lang.ClassFormatError
Then I tried to manually load the applet class file on the ZMI and it
worked. Printing the filesystem path reveals that it is correctly
separated with "\". But, some how, manage_addFile corrupts the file on
Windows.
The code is attached to the message. Does somebody knows what the error
could be?
Thanks in advanced,
Josef
-------------- next part --------------
__doc__="""Misc utilities"""
__version__ ='$Revision: 0.1 $'[11:-2]
#File: Misc.py located on Products/JMUtils
DATA_BASE_PATH='/JMFiles'
def _createFileInFolder(context, filePath, fileName,
zopePath, title=''):
"""Creates a the folder <zopePath> and puts the
file <filePath>/<fileName> on it
"""
pathLen=len(zopePath)
#Remove leading slash
if (zopePath[-1]=='/') and (pathLen>1):
zopePath=zopePath[0:pathLen-1]
if zopePath[0]!='/':
#The product will only work with relative paths
#if the instances can adquire them.
log('The path "%s" is relative.' %zopePath,
severity=WARNING,detail='For better results use absolute paths.',
product='createFileInFolder')
zopePath='/'+zopePath
pathParts=os.path.split(zopePath)
basePath=pathParts[0]
folder=pathParts[1]
#This only happens when no slash is given at
#the beginning of the path, so the root will
#be assumed
fileContainer=context.unrestrictedTraverse(basePath,None)
if fileContainer==None:
log('The path "%s" doesn\'t exist on the Zope DB.' %basePath,
severity=PROBLEM,detail='Create it first.',
product='createFileInFolder')
return
fileFolder=fileContainer
#If the given path wasn't the zope root
if folder!='':
try:
manage_addFolder(fileContainer,folder,'JMFiles')
except:
#The Folder already exists
pass
fileFolder=getattr(fileContainer,folder)
absolutePath=os.path.join(filePath,fileName)
data=file(absolutePath)
try:
manage_addFile(fileFolder,fileName,file=data,
title=title)
except:
#The file was already created on a previous session
pass
I called it on the __init__.py of my Product:
__doc__="""JMColorPicker initialization module."""
__version__ ='$Revision: 0.1 $'[11:-2]
#File __init__.py located on Products/JMColorPicker
from JMColorPicker import JMColorPicker, manage_addJMColorPickerForm, \
manage_addJMColorPicker
from Products.JMUtils import Misc
import Globals, os
PRODUCT_HOME=Globals.package_home(globals())
def initialize(context):
try:
context.registerClass(JMColorPicker,
constructors=(
manage_addJMColorPickerForm,
manage_addJMColorPicker,
),
icon='images/icon.gif',
)
context.registerHelp()
#The applet is under "PRODUCT_HOME/java"
absolutePath=os.path.join(PRODUCT_HOME,'java')
appContext=context._ProductContext__app
Misc._createFileInFolder(appContext,absolutePath,'ColorPicker.class',
Misc.DATA_BASE_PATH,title='ColorPicker Applet')
except:
from sys import exc_info, stderr
from traceback import format_exception
from string import join
type,val,tb=exc_info()
stderr.write(join(format_exception(type, val, tb),''))
del type,val,tb
More information about the Zope
mailing list