Java Jpype Absolute tutorial
Date: MarpmSun, 08 Mar 2009 14:08:45 -0500 83102,2009 1:01:04 - Subscribe
Mood: Happy
Personal: Java and jpype


this tutorial tells basic usage of jpype , calling java class with python

suppose java file is this

..................................................................................................................................................................

package com;

class lohi
{
public lohi(String name){}
public static void main(String str[])
{
System.out.print("welcome\n");
}
public void look()
{
System.out.print("Ashish");
}
}
...................................................................................................................................................................

compile this code and add the class file lohi.class is folder "c:\com\" now python code


import jpype
import os.path
jarpath = os.path.join(os.path.abspath('.'), '.')
jpype.startJVM("C:/Program Files/IBM/Java50/jre/bin/classic/jvm.dll", "-ea","-Djava.class.path=C:/")
testPkg = jpype.JPackage('com')
lohith=testPkg.lohi
l=lohith("ashish")
l.look()
jpype.shutdownJVM()


run this code and it will work


you have to change "C:/Program Files/IBM/Java50/jre/bin/classic/jvm.dll" to your system jvm path

......................................................................................................................................................................
after facing lot of errors i got this code working . and doubts please feel free to mail me lookforlohith@yahoo.co.in
Comments: (1)


Sky Template
Free Blog Hosting Join Today
Content Copyrighted lohith at Aeonity Blog
Comments:

anonymous - January 22nd, 2017
Please help me, after execution of last line I am getting below error
Python35\lib\site-packages\jpype\_jpackage.py", line 56, in __call__
raise TypeError("Package {0} is not Callable".format(self.__name))
TypeError: Package com.lohi is not Callable

Sorry anonymous, this user does not allow double comments to be posted.