471,571 Members | 1,366 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,571 software developers and data experts.

Call Java Methods from Python Script


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:

Expand|Select|Wrap|Line Numbers
  1. from jpype import *
  3. startJVM("C:\Program Files\Java\jdk1.6.0_12\jre\bin\client", "-ea", "-Djava.class.path=%s" % classpath)
  4. com =JPackage("CallJavaFromPython")
  5. jp = com.Jpype1()
  6. jp.printArgument("XXX")
  7. shutdownJVM()
================================================== =

Expand|Select|Wrap|Line Numbers
  1. package CallJavaFromPython;
  3. public class Jpype1 {
  5. public static void main(String args[]){
  6. System.out.println(args[0]);
  7. }
  9. public void printArgument(String arg){
  10. System.out.println(arg);
  11. }
  13. }
================================================== =

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...
Feb 18 '09 #1
1 4814
It's probably because you named your own program Jpype.py which is not a good idea. Thus the line:

from jpype import *

does not do what you expect.

Mar 15 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Dave Kuhlman | last post: by
3 posts views Thread by Alexander Fillips | last post: by
1 post views Thread by Stacey | last post: by
46 posts views Thread by Steven T. Hatton | last post: by
9 posts views Thread by Daniel Gee | last post: by
11 posts views Thread by BigZero | last post: by
1 post views Thread by replysonika | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.