Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Calling java from python

843785Feb 18 2009 — edited Feb 19 2009
Hi,

I am trying to call java methods from a python script. Jython is not an option. I have looked at using Jpype. Below is my code thus far:

Jpype.py

from jpype import *

startJVM("C:\Program Files\Java\jdk1.6.0_12\jre\bin\client", "-ea", "-Djava.class.path=%s" % classpath)
com =JPackage("CallJavaFromPython")
jp = com.Jpype1()
jp.printArgument("XXX")
shutdownJVM()

================================================== =

Jpype1.class

package CallJavaFromPython;

public class Jpype1 {

public static void main(String args[]){
System.out.println(args[0]);
}

public void printArgument(String arg){
System.out.println(arg);
}

}

================================================== =

Error message i am getting when I try to run the python script is :

NameError: name 'startJVM' is not defined


has anyone come across this before?

Thanks in advance...

Comments

794069
Why is jython not an option?
843785
Those startJVM and shutdownJVM methods: are they standard Python?
843785
The most recent release of Jython does not support above Python 2.3. There is a beta version released but it is not possible for me to use this. Otherwise it would be perfect.
843785
As far as I know they are not standard and come as part of the jpype package which I have imported.
843785
hofsoc wrote:
As far as I know they are not standard and come as part of the jpype package which I have imported.
My guess is that you haven't done that properly
794069
hofsoc wrote:
The most recent release of Jython does not support above Python 2.3. There is a beta version released but it is not possible for me to use this. Otherwise it would be perfect.
Ok, that's a drag. Any chance you can use an earlier version of Python?
1 - 6
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Mar 19 2009
Added on Feb 18 2009
6 comments
283 views