By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,089 Members | 2,418 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,089 IT Pros & Developers. It's quick & easy.

Call Java Methods from Python Script

P: 2
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
Share this Question
Share on Google+
1 Reply


P: 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.