0

I am using JPype The following is the code i am trying to use

from jpype import *

startJVM("C:\Program Files\Java\jdk1.6.0_14\jre\bin\client\jvm.dll","-ea")
java.lang.System.out.println("hai")
shutdownJVM() 

It is giving error in the execution of the println statement

java.lang.System.out.println("hai")
File "<stdin>", line 1
java.lang.System.out.println("hai")
                                   ^
SyntaxError: invalid syntax 
JK.
  • 21,477
  • 35
  • 135
  • 214
Rajesh Kumar J
  • 4,745
  • 6
  • 26
  • 25
  • Can you please share a working sample of executing class' function of a jar from Python using Jpype. I was not able to find a working sample, tried a couple of with options but fail with error 'not callable' – Sankalp Jan 22 '17 at 19:24

2 Answers2

-1

Firstly, are all the dependencies setup correctly? Java, Python, JPype etc?

You are trying to execute one of the first examples in the documentation.

The sample they provide in the docs are:

from jpype import * 
startJVM("d:/tools/j2sdk/jre/bin/client/jvm.dll", "-ea") 
java.lang.System.out.println("hello world") 
shutdownJVM()

One of the main differences is that you are using \ as a path separator. As per the docs, maybe try a /.

gpampara
  • 11,989
  • 3
  • 27
  • 26
  • Now i change my code to startJVM("C:/Program Files/Java/jdk1.6.0_14/jre/bin/client/jvm.dll","-ea") Still it is giving the same error >>> java.lang.System.out.println("hello world") File "", line 1 java.lang.System.out.println("hello world") ^ SyntaxError: invalid syntax – Rajesh Kumar J Jan 11 '10 at 06:43
-2

Looks like you might just be missing a semicolon (;)

Tyler
  • 21,762
  • 11
  • 61
  • 90