-1

I am trying to call java class from a jar file in python. I've see people talking about programs like Jython, Py4j, Jpype, etc, but I am hoping for an easier way other than spend lots of time to study a new program. I am new to programming. Thanks.

Briefly, here is what I want to accompolish. Say a jar file called 'Converter.jar'. It has a function 'parse' in a class 'Handler'. How can I call the jar file to realize something like Converter.Handler.parse('my file')?

Jian
  • 365
  • 1
  • 6
  • 19
  • 1
    I don't know enough about Java to offer concrete help, but http://stackoverflow.com/questions/476968/using-a-java-library-from-python looks highly relevant. – Mark Amery Dec 15 '14 at 17:05
  • 3
    Python is not designed to interface with Java. You're going to have to use something specially designed for this. Jython runs under Java normally, and so should have a built in way of doing this. Alternatively, Py4j and JPype appear to be libraries designed to allow interface with Java from CPython. – jpmc26 Dec 15 '14 at 17:15

1 Answers1

0

You can use Jython for this specific purpose(much easier than you think), below is an example:

import sys
sys.path.append("<path_to_jar_file>")
import <package>

A link which is a relevant reference to topic in hand is - link.

nitishagar
  • 9,038
  • 3
  • 28
  • 40