-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')?

2
  • 1
    I don't know enough about Java to offer concrete help, but stackoverflow.com/questions/476968/… looks highly relevant. Commented Dec 15, 2014 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. Commented Dec 15, 2014 at 17:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This example just registers the jar file to the sys path. Is CPython required for Jython?
The link has died, an updated link would be nice

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.