Getting started with JPype

P

porter

Hi,

For nefarious javaesque reasons I've been trying to get started with
jpype (http://jpype.sourceforge.net). This looks like a potentially
useful tool for integrating java classes into C-python, but
frustratingly I've run into immediate problems. The documentation on
the project really doesn't deal with 'the basics' and I believe it is
this that I am running foul of: I have read much on the web, and I
suspect that this is a classpath issue, but I can't see what I'm doing
wrong.

And I'm confident that the path I specify is ok

The error I get is

"Package myclass.HelloWorld is not Callable"

but I suspect that this is, infact, telling me that the class
HelloWorld could not be found.

If so - why not? - Note that using java

Here's my python code snippet

from jpype import *

startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=D:/tmp/jpype-
reli/test/dist/test.jar'' )

package = JPackage("myclass")
x = package.HelloWorld()
x.do_a_message()

shutdownJVM()

I have a java class called HelloWorld in package "myclass" which
resides in test.jar. The source is below:

package myclasses;

public class HelloWorld
{

/** Creates a new instance of HelloWorld */
public HelloWorld()
{
}

public void message()
{
System.out.println("Hello, World");
}

public static void do_a_message()
{
System.out.println("Static Hello, World");
}
}
 
P

porter

Gah - I hate it when that happens: Just after posting I figured out my
silly mistake: my package is called myclasses and I was referencing
'myclass'

apologies for wasting your time
 
I

Ian Clark

Disclaimer: I have never used (or even heard of) JPype before...

porter wrote:
(snip)
"Package myclass.HelloWorld is not Callable"
(snip)

from jpype import *

startJVM(getDefaultJVMPath(), "-ea", "-Djava.class.path=D:/tmp/jpype-
reli/test/dist/test.jar'' )

package = JPackage("myclass")

Shouldn't this be `package = JPackage("myclasses")` as your Java code is
contained in the package 'myclasses' not 'myclass'?
x = package.HelloWorld()

Change this last line to: `x = package.HelloWorld`
(class would be a better name than x IMO)
x.do_a_message()

shutdownJVM()

It looks like JPype exports Java classes as members of the object
referred to by `package`. You then try and call it with () and python
throws it's hands in the air as it must not be a callable.

Ian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top