I am using following code Snippet to invoke the function present in jar file. but i am unable to connect the class.
Development Env:
Python: Python27,32bit jpype Version(JPype-0.5.4.2.win32-py2.7.exe)
Java: jre1.8.0_60,32bit.
Java Code:
public class Samp {
public Samp() {
super();
}
public String sayHi()
{
return("Hello");
}
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println ("Hello world");
}
public static int add(int a, int b)
{
return(a+b);
}
}
C:\temp\tem\samp.jar Jar file is presen in that directory. I am Connecting jar file using below code.
python Code:
>>import jpype
>>jpype.startJVM(jpype.getDefaultJVMPath(), '-ea', '- Djava.class.path=c:\\temp\\tem')
>>A = jpype.JClass("Samp")
>>a = Samp()
>>print a.sayHi()
>>jpype.shutdownJVM()
By running above code,I am getting following error
Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\jpype_jclass.py", line 54, in JClass raise _RUNTIMEEXCEPTION.PYEXC("Class %s not found" % name) jpype._jexception.ExceptionPyRaisable: java.lang.Exception: Class Samp not found