This page is about setting up the Eclipse IDE for writing Java and Python programs that use the UACalc Java classes. (If you prefer to write programs in a text editor or Emacs, please refer to this set of notes instead.)
Eclipse is a powerful Integrated Development Environment (IDE) that makes programming in many languages, like Java, much easier. It can be configured so you can easily use the UACalc Java classes in your own programs, and even make your own contributions to UACalc.
Eclipse can also be configured so that it’s easy to develop Python programs that make use of UACalc Java classes.
This page shows how to setup Eclipse for these two development methods. Specifically, we give instructions for setting up the Eclipse IDE with the Java Development Kit (JDK 1.7), PyDev, and Jython on Ubuntu 12.04 (64 bit). It is not necessary to use Eclipse to program with the UACalc Java classes, but they can be helpful for those who prefer a feature rich graphical development environment.
The setup described on this page is an alternative to the Emacs setup that will be described in another set of notes on this site.
WARNING: The author of these notes uses Ubuntu Linux exclusively, so these instructions are primarily intended for Linux users. If you use another operating system, feel free to use these notes as a guide, but you will need to modify many of the steps to suit your environment. If you are willing to contribute alternative instructions that work for your environment, please post a comment in the box below so we can arrange this.
If you have any comments, questions, or suggestions for improvements, please post them in the box at the bottom of this page.
- Java Development Kit installation and setup
- Eclipse installation and setup
- Java programming with UACalc classes
- Jython and PyDev installation and setup
- Python programming with UACalc classes
- Other Resources
Java Development Kit (JDK) installation and setup
As of this writing (June 7, 2013) the latest version of the JDK is 1.7, which is available here. The first steps below basically follow the standard installation instructions, with a few ubuntu-specific modifications.
- Download JDK 1.7. (For me this was jdk-7u21-linux-x64.tar.gz.)
- Unpack the jdk tarball (in a directory under your home directory for now—we’ll move it after). Use the command
tar xvzf jdk-7u21-linux-x64.tar.gz
- Create the directory /usr/lib/jvm with the command
sudo mkdir -p /usr/lib/jvm
- Move the unpacked jdk directory to /usr/lib/jvm/jdk1.7.0 with a command like:
sudo mv jdk1.7.0_21 /usr/lib/jvm/jdk1.7.0
(assuming your jdk directory was named jdk1.7.0_21)
You can choose which version of Java will be used on your system using the update-alternatives program. For details, see notes on configuring JDK 1.7 on Ubuntu. For example, to make my system use the version installed above, I used the following commands:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1 sudo chmod a+x /usr/bin/java sudo chmod a+x /usr/bin/javac sudo chmod a+x /usr/bin/javaws sudo chown -R root:root /usr/lib/jvm/jdk1.7.0 sudo update-alternatives --config java sudo update-alternatives --config javac sudo update-alternatives --config javaws
You can check which version of Java your system is currently using with the command java -version.
Eclipse installation and setup
This section explains how to install Eclipse from scratch on Ubuntu 12.04. If you have already installed a version of Eclipse and just want to upgrade, you should either modify these steps (or skip them altogether) so that you don’t loose your existing configuration files and workspace. In particular, the first step below is not absolutely necessary, and you can certainly have multiple installations of Eclipse on your machine. (For example, you could use update-alternatives program, as we did above for Java.)
- Remove existing versions of Eclipse from your system. You can do this either with a package manager or at the command line in a terminal window.
- At the command line Open a terminal window and enter the apt-get command below. (The –purge option removes both packages and their configuration files, so later we will have a completely fresh install of Eclipse; if you want to keep your config files, leave off the –purge option.)
sudo apt-get --purge remove eclipse eclipse-platform eclipse-platform-data eclipse-rcp eclipse-pde eclipse-cdt eclipse-cdt-jni eclipse-rse libecj-java eclipse-jdt eclipse-emf
- With a package manager
- Open a package manager (e.g., Synaptic or the Ubuntu Software Center).
- Search for and mark for complete removal all eclipse packages. Specifically, remove the following: eclipse, eclipse-platform, eclipse-platform-data, eclipse-rcp, eclipse-pde, eclipse-cdt, eclipse-cdt-jni, eclipse-rse, libecj-java, eclipse-jdt, eclipse-emf. (Complete removal removes both the packages and their configuration files.)
- Click Apply and, once the removal is finished, close the package manager.
- Download the latest release of Eclipse from the Eclipse Download Page. I recommend downloading either Eclipse IDE for Java Developers, or Eclipse IDE for Java EE Developers. (Tip 1: Don’t waste time mulling this over, since you can easily add/remove eclipse packages later. But if you want, you can check out the table comparing Eclipse distributions. Tip 2: The download will only take a minute or two if you use a torrent file. Not all mirrors offer a torrent download option, but if you search around the download area, you might see a torrent file link. If you’re using Linux 64 bit, this link works as of October 2013.)
- Unpack the file you downloaded in the previous step with the tar command. For example,
tar xvzf eclipse-java-kepler-R-linux-gtk-x86_64.tar.gz
- This creates a directory called eclipse. Move this directory wherever you want. (I put it in $HOME/opt/eclipse, and the remaining steps below assume this.)
- Either add $HOME/opt/eclipse to your $PATH, or create a link to the eclipse startup program and place it in a directory that is already in your path. That is, either execute the command
or the command
ln -s $HOME/opt/eclipse/eclipse $HOME/bin/eclipse
(If you chose the export command above, add this command to the bottom of your $HOME/.profile file.)
- This completes the installation of Eclipse.
Typing eclipse at the command line should launch the Eclipse IDE, and you should be greeted by a Welcome screen like this one:
(If it doesn’t work for you, please post a comment at the bottom of this page.)
Finally, when you launch Eclipse from the command line, the icon for Eclipse may show up in the Unity dock as a question mark. If you want to fix this, please read the notes below on “Creating an Eclipse launcher button in the Unity dock.”
Creating an Eclipse launcher button in the Unity dock
If you installed Eclipse as above, then typing eclipse at the command line should launch the Eclipse IDE, which will ask you where the Eclipse workspace directory should reside, and then present you with the Welcome screen.
The icon that appears in the Unity dock on the left might be a question mark, instead of the appropriate Eclipse icon. To fix this, and to make a permanent Eclipse button in the Unity dock, follow the advice provided at http://askubuntu.com/questions/80013/how-to-pin-eclipse-to-the-unity-launcher
I chose to follow Bruno Pereira’s advice and executed the following:
mkdir -p ~/.local/share/applications gnome-desktop-item-edit --create-new ~/.local/share/applications/
In the dialog box, I chose Eclipse as the name, specified the path to the eclipse binary, clicked on the icon, and chose the icon at $HOME/opt/eclipse/icon.xpm.
The dialog box should look like this (before you click on the launcher icon to replace it):
After clicking the launcher icon and replacing it with $HOME/opt/eclipse/icon.xpm, the dialog box looks like this:
After clicking okay, I invoked the following from the command line:
and then drag-and-dropped the new Eclipse item into the launcher.
In the Command: field of the launcher dialog box, you can insert command line options; for example, `eclipse -vmargs -Xmx2048M` will increase the heap space. See this page for an explanation.
Java programming with UACalc classes
Importing the UACalc source code into Eclipse
From within Eclipse the following:
- File –> Import…
- Select from the list: CVS –> Project from CVS, then click Next.
- If you have never set up a CVS repository in Eclipse, skip to Step 4. Otherwise, select “Create a new repository location,” then click Next.
- Fill in the fields as follows:
- Host: uacalc.cvs.sourceforge.net
- Repository path: /cvsroot/uacalc
- User: anonymous
- Connection type: pserver
then click Next.
- Select “Use an existing module.” When uacalcsrc shows up, select it and click Finish.
You should see a progress dialog box showing you that uacalcsrc is being checked out of CVS. Once the checkout is complete, you will probably have errors, such as, “The project cannot be built until the build path errors are resolved.” (see below)
Fixing the Build Path Errors:
- Right-click on the name uacalcsrc in the Package Explorer pane on the left and select Properties.
- In the dialog box that appears, select Java Build Path, click on the Libraries tab and then click the Add Jars button.
- Expand the uacalcsrc folder, expand the jars folder, and select miglayout-3.7-swing.jar and click OK.
- On the Libraries Tab, make sure the JRE System Library (e.g., jdk1.6.0_10) does not say “(unbound)” next to it. If it does, click the Add Library button, select JRE System Library, and click the Workspace Default radio button. (This should be the JRE System Library that you normally use when compiling java programs with Eclipse.)
- Select the (unbound) JRE System Library (the one with the red x next to it), and click Remove.
- Finally, click the okay button to exit out of the Properties dialog.
- If there is still a red exclamation point next to the name uacalcsrc, right-click on the name uacalcsrc and selecting Refresh.
Adding your own class(es):
- A good place to add them is the package org.uacalc.example. Right click on this package and choose New –> class.
- The class HasKaryNU, contributed by Matt Valeriote, tests in polynomial time if an idempotent algebra has a k-ary nu term for a given k. Eclipse can run these programs (right click and choose Run as .. java app). You will need to change the name of the algebra file.
Jython and PyDev installation and setup
There are two implementations of the Python language. One is written in C, called CPython or “classic Python”, and the other is written in Java, called Jython. This section shows how to configure Eclipse so that you can use it as an IDE for Jython programming.
IMPORTANT: The version of jython that comes with ubuntu does not work with Eclipse right out of the box. At the very least it requires additional configuration. For simplicity, we will remove this version of jython and install the latest version that is available at Jython.org.
- Open up a package manager and search for jython. If jython is installed, mark it for complete removal. (While you’re at it, you can also install python 2 and python 3 if you like, though we won’t use them below. It seems the ubuntu python packages work fine with Eclipse, unlike the ubuntu jython package.)
- Go to Jython.org and download the jar files (e.g. jython-installer-2.7-b1.jar)
- cd to where you downloaded the jar file in Step 2 and type java -jar jython-installer-2.7-b1.jar and follow the instructions. (Choose to install everything including sources.)
- Add the directory where you chose to install jython to your path by appending something like the following to your ~/.profile file: ‘export PATH=$PATH:$HOME/opt/jython/jython2.7b1/bin’
- At the command line, type ‘source ~/.profile’ so that jython is in your path.
- At the command line, start the jython interpreter by typing ‘jython’
- If you get the >>> prompt, it means Jython is installed. Exit Jython with the quit() command.
- Launch Eclipse and install the PyDev plugin by following the instructions in the Jython Book in Chapter 11. Using Jython in an IDE. Follow the steps in both of the sections “Installing PyDev” and “Minimal Configuration.”
Python programming with UACalc classes
This section assumes you have already installed Jython, Eclipse, and the PyDev plugin (as described above), and have created a new PyDev project in Eclipse. The goal of this section is to demonstrate how one adds to an existing project the ability to import and make use of external Java classes like those in the UACalc distribution. (Use either Method 1 or Method 2. It’s not necessary to do both.)
WARNING: These instructions may or may not work for you. I have had success with them on some machines, and not on others. I think part of this is due to the fact that many configuration changes in Eclipse require that you restart Eclipse for them to work properly, but Eclipse does not always tell you when such restarts are necessary.
If these methods do not work for you (and even if they do), keep in mind that Eclipse is not the only option for UACalc programming, and you may wish to read the notes on this site that describe how to use the Jython command line interpreter and Emacs for Python programming with UACalc classes.
Method 1 (using Eclipse and uacalc.jar)
- Get the uacalc.jar file by pointing your browser to http://www.uacalc.org/lib/uacalc.jar and take note of the directory to which you download it.
- In Eclipse, select your existing PyDev Jython project in the Package Explorer and type Alt+Enter. This brings up the Properties dialog.
- Select the PyDev – PYTHONPATH, and click on the External Libraries tab. Then click the Add zip/jar/egg button, locate the uacalc.jar file you downloaded in Step 1, and select it.
- After clicking OK, you are almost ready to start importing UACalc classes into Python programs. To complete the configuration, you must go to the File menu and select Restart. When Eclipse restarts, you should be ready to import UACalc classes into your .py files with lines like the following:
from org.uacalc import alg
Method 2 (using Eclipse and the UACalc source)
- Import the uacalc source code into Eclipse by following the commands described at http://www.uacalc.org/download/
- Right click on your existing PyDev Jython project in the Package Explorer and select Properties (Alt+Enter) from the menu.
- In the left pane of the Properties dialog box, select Project References and then check the box next to uacalcsrc. The dialog box should look something like this:
- Click the OK button and then (important!) restart Eclipse. When Eclipse restarts, you should be ready to import UACalc classes in your .py files with lines like the following:
from org.uacalc import alg
In case your Jython programs are not running as you would expect from within Eclipse, check your PyDev intepreter settings, as follows:
- In Eclipse, from the Window menu, select Preferences.
- In the Preferences dialog, expand the PyDev entry in the left window pane and select “Interpreter – Jython”
- Make sure that in the top right “Jython interpreters” window it says Jython 2.7 (or whichever Jython version you expect).
- In the bottom right “System PYTHONPATH” window pane the system libraries should match the JRE that you have setup as your default for Eclipse. For example, if jdk1.7.0 is your default JRE, but in the PYTHONPATH pane you see entries containing /usr/lib/jvm/java-6-sun-188.8.131.52/jre/lib … this will cause problems.This is good:This is bad:
- Mark Dexter’s Eclipse Tutorials. Long but very good intro to Java Test Driven Development.
- My personal Eclipse setup notes. I wrote these for my own reference, and they were never intended for public consumption. Nonetheless, you might find them useful, especially for setting up Eclipse to work well with GitHub.
- Jython Essentials. A nice introduction to Python programming (with Jython specific details).