469,314 Members | 2,182 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

Call Java Methods from Python Script

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
Expand|Select|Wrap|Line Numbers
  1. from jpype import *
  2.  
  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()
  8.  
================================================== =

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

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 4678
kaer
1
@hofsoc20
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
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.