Using java with your jython project? Here is a quick tutorial on how to import java jar’s into the project for auto completion and an overall better experience with intellij.
Get Jython
First Off, install your jython interpreter from here:
http://www.jython.org/downloads.html
For this project, I used the installer because it was easier, however the standalone jar will work perfectly fine, but some of the steps below will be slightly different.
Download the installer and select the ‘Standard’ install. As usual, you’ll need to accept some license agreements. For the install path, I usually put these right in my C:\ directory because I have a few different ones installed on my machine and this makes it easier.
After the install, you’ll have the jython files in the C directory:
Create the Jython Project and Setup
Open up intellij and create a new project. Go to File – New – Project…
Then we’ll just select an empty project in case the python interpreter is not setup.
Just name the project whatever you want and continue with the process.
It will prompt you to add a module after creation since we chose an empty project. Here is where we will need to add the jython sdk to the project.
Go the project option on the left, and then click the ‘New…’ button.
Then select ‘Python Sdk’.
And if asked say ‘Add Local’.
Now we have to find the Jython files we installed. Select the bin/jython.exe file and click ‘Ok’
Now you’ll have jython ready to go and you can write basic python in intellij.
Adding in Java Libraries
The main advantage of Jython over Python is the ability to use java libraries in the code. However, we’ll need to tell intellij where to find these libraries because jython capabilities aren’t standard.
Go to the ‘Libraries’ section of the Project Settings and click the green ‘+’ symbol
Now you’ll have to find your java JDK on your system. If you don’t have one, then install it from oracle on this page:
(If you know what you’re doing here, feel free to only install the JRE. It’s just easier to install the jdk and jre.)
For me, I throw all of these library types in the C:\ folder so mine was easy to find. The folder we want to select will be in the jdk/jre folder, and it is called lib. Make sure you select the whole folder and click ‘OK’
Now Intellij knows where to look for dependancies and can index them, which allows for auto-completion.
Get Down and Code
Now you’re ready to code! Create a new module with the added Jython SDK. You can find this prompt in ‘File’ then ‘New’ and then ‘Module…’. Make sure to select the ‘Python’ selection on the left. Name the module whatever you need it to be.
Next, create a new file called whatever you would like, just make sure to put the ‘.py’ on the end to signify a python (really jython in this case) file.
Now we get to experience the best of both worlds. A simple scripting language like Python, the flexibility of java, and the auto-completion features of Intellij!
This works for the basic java libraries, as well as any custom java jars you have created. So custom code can be utilized with auto-completion as well.