Getting started with JPype

porter cole at ccdc.cam.ac.uk
Mon Aug 13 10:25:11 EDT 2007


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




> 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");
>     }
>
> }





More information about the Python-list mailing list