[Zope] Using Java objects with the JPE
Riggs, David
driggs@asset.com
Thu, 13 Jun 2002 17:24:13 -0400
I've now got Zope interacting with Java objects (and very smoothly in
fact). Since I havn't seen any good info on setting this up, and since
the JPE is very poorly documented, here's how I did it:
1. Acquired binaries of the JPE. Only source code is provided on the
website, and the python modules must be built with MS Visual C, so I was
not able to compile this myself. Chris Withers was kind enough to
provide a compiled version to me, I'll happily send this out to anyone
that would like it.
2. Dropped the python module directory (called 'java/') into
zope/lib/python/.
3. Added my Java classes and .jars to my CLASSPATH, in this case I just
added it to the beginning of the Zope startup batch file.
4. Created a small python script (TrainingView.py) and dropped it into
zope/Extensions/. It looks like this:
import java
from java.jvm import isInitialized, initialize
from java.jobject import importClass, Jobject, Jstring, javalib
if not java.jvm.isInitialized():
print 'JVM not initialized, initialize()ing...'
java.jvm.initialize()
def getTrainingView( action=3D'', user=3D'', pass_=3D'' ):
TrainingView =3D
importClass('com.saic.ewing.training.TrainingView')
myObj =3D TrainingView()
return myObj.getTrainingView( Jstring(action),
Jstring(user), Jstring(pass_) )
4.5 Restart Zope :)
5. Create an external method that looks like this:
ID: trainingApp
Module Name: TrainingApp
Function Name: getTrainingView
6. I post to the external method with a form that has eg. <input
name=3D'action' type=3D'text'> and the String that my Java object =
returns is
displayed! This particular Java object does a remote procdure call via
SOAP, then does an XSL transorm on some XML and spits HTML back as a
string.
Good stuff!
David A. Riggs
Science Applications International Corporation - SAIC
(304)284-9000x201 driggs@asset.com
-----Original Message-----
From: Dieter Maurer [mailto:dieter@handshake.de]=20
Sent: Wednesday, June 12, 2002 1:56 PM
To: Riggs, David
Cc: zope@zope.org
Subject: Re: [Zope] Using Java objects with the JPE
Riggs, David writes:
> I'm trying to access some existing java objects through python with
the
> python JPE library. I'm able to use these objects fine from the
python
> command line, but I've spent hours trying to set things up with zope
and
> have had no luck.
>=20
> Where do I put the JPE libraries for Zope to find them? I've got them
> under lib/Python/java right now. Do I need to add them as a Product?
Please search the mailing list archives (or the Python documention)
for PYTHONPATH. It is this environment variable that you need to
extend to let Zope find the Python modules and share objects of JPE.
I did not yet use JPE. Thus, it might also be the other way round.
> Where do I put my java classes for the JPE to find them? I'm assuming
> that they just need to be relative to my system CLASSPATH.
Yes, try this.
> Like I said, I've got everything working from the command line...
How do you do it?
Do you start Python and then load a JPE module or do you start
JPE and tell is to activate a Python interpreter?
Dieter