Using Java in a Jython Project
A mixed Jython-Java project is typically created to use the project's Java classes in the project's Jython modules. Here are the steps to setup a mixed Jython-Java project so that the Java classes are found when a Jython module is run.
Note: At this time, JyDT does not provide the ideal solution, which would be the ability to add the Java build path to the Jython system path.
- Assume that you have set up a mixed Jython-Java project.
In the example project below, the Java project uses "src" as the Java source folder,
"bin" as the output folder,
and "jython" as the Jython source folder.
- Further assume that the files "TestClass.java" and "test.py" contain the following source code.
The Jython module defines a class that inherits from the Java class and overrides a method.
(Do not mind the error marker on the import statement. That is a limitation of JyDT at this time.)
- Open the "Jython Class Path" in the properties of the project. Add the "bin" folder by pressing
"Add Folder" button. Here the note from the beginning of the page comes in: the path to the
"bin" folder is not relative to the project, which is not desired, but it works in the current
version of JyDT.
- Select the module "test.py" and choose "Run As > Jython" from the "Run" menu or from the toolbar.
- The module is executed. The output on the console is as expected.
- Let's have a look at the run configuration. Eclipse has recognized the folder entered in
the Jython class path as a folder in the project ("bin - \Mixed Java-Jython Project\").