Using Python from within Java [duplicate] Using Python from within Java [duplicate] python python

Using Python from within Java [duplicate]


I'm aware of the Jython project, but it looks like this represents a way to use Java and its libraries from within Python, rather than the other way round - am I wrong about this?

Yes, you are wrong. You can either call a command line interpreter to run python code using Jyton or use python code from Java. In the past there was also a python-to-Java compiler, but it got discontinued with Jython 2.2


I would write a Python module to handle the text and language processing, and then build a small bridge in jython that your java program can interact with. The jython bridge will be a very simple one, that's really only responsible for forwarding calls to the python module, and return the answer from the python module to the java module. Jython is really easy to use, and setup shouldn't take you more than 15 minutes.

Best of luck!


I don't think you could use NLTK from Jython, since it depends on Numpy which isn't ported to the JVM. If you need NLTK or any other native CPython extension, you might consider using some IPC mechanism to communicate between CPython and the JVM. That being said, there is a project to allow calling CPython from Java, called Jepp:

http://jepp.sourceforge.net/

The reverse (calling Java code from CPython) is the goal of JPype and javaclass:

sourceforge.net/projects/jpype/

pypi.python.org/pypi/javaclass/0.1

I've never used any of these project, so I cant't vow for their quality.