Hi,

I wanted to see how well Python and Java would work together so I wrote a little Minesweeper game in Python (Jython) plus a GUI in Java. I used Eclipse with PyDev too make things easier.

I followed this tutorial
http://www.jython.org/jythonbook/en/1.0/JythonAndJavaIntegration.html#using-jython-within-java-applications
and wrote a Java factory to be able to use my Jython minesweeper class from Java.

The first problem was importing the Python class in the Python interpreter.

PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("from logic.minesweeper import minesweeper");

This produced the following error:


Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named minesweeper

I solved this by first modifying the search path:

PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import sys");
interpreter.exec("sys.path = [''] + sys.path");
interpreter.exec("from logic.minesweeper import minesweeper");

Now my problem is that everything works fine as long as I run the programm from eclipse, but when I export the project as a runnable jar the program won't start anymore.
I suppose the problem is my little hack which doesn't work for the runnable jar.

What would be the right way to ensure the Interpreter finds the Python class? How do I make this work for runnable jars as well?


Here are some more infos in case they are important:

Project structure:
gui/MainWindow.java
logic/__init__.py
logic/minesweeper.py
logic/MinesweeperInterface.java
logic/MinesweeperFactory.java

There are no seperate src/bin folders (since that seemed to cause problems).

I added the jython.jar to the java build path (jython2.5.2)
The Python minesweeper class (in minesweeper.py) implements the Java MinesweeperInterface:
from logic import MinesweeperInterface
class minesweeper(MinesweeperInterface):
    ...

I'm new to Python/Jython, so sorry íf I'm missing something obvious here.

I appreciate your help. Thank you!
Steffen Smolka