One of the most enjoyable courses I took during the Imperial MSc in Computing Science I did from 2010-2011 was the Robotics course. Every week we learnt about a cool new technique in a lecture and then we put that new technique into practice. My group decided to abandon “Robot-C” compiler and instead use a Java implementation called NXJ.  Below are my notes on configuring Eclise, SVN and NXJ to work on the Imperial Ubuntu Linux machines.

Install Subclipse (Eclipse’s SVN client) {#internal-source-marker_0.5452003090684711 dir=”ltr”}

  1. Help > Install New Software
  2. Enter this URL:
  3. Add Subclipse
  4. Once Subclipse is installed, you’ll also need to install the javaHL library

Install leJOS NXJ plugin for Eclipse {#install-lejos-nxj-plugin-for-eclipse dir=”ltr”}


Eclipse configuration {#eclipse-configuration dir=”ltr”}

Making Eclipse indent code in an Emacs-compatible way (so other team members can continue to use Emacs) {#making-eclipse-indent-code-in-an-emacs-compatible-way-so-other-team-members-can-continue-to-use-emacs dir=”ltr”}

Set Eclipse to use spaces instead of tabs (so the code generated by Eclipse looks OK in Emacs).  Go to Window > Preferences > Java > Code Style > Formatter.  Edit the code style and set “tab policy” to “spaces only” and set “tab size” to 8.  Save the code style with a new name.

Tell Eclipse not to automatically import
Windows > Preferences > Java > Editor > content Assist
uncheck “add import instead of qualified name”


NXJ JavaDocs within Eclipse {#nxj-javadocs-within-eclipse dir=”ltr”}

Within Eclipse, right-click on your Robotics project and go to:


Properties > Java Build Path > Libraries


Click on the “>” icon to the left of “classes.jar” and select “Javadoc location”.  Click “edit” and enter:

Eclipse should now be able to give you useful information about NXJ classes and member functions if you hover over the functions (note that if you click on “Validate” then it’ll claim the URL doesn’t validate… but it still seems to work)


Environment variables (for our Imperial DoC machines running the tcsh shell) {#environment-variables-for-our-imperial-doc-machines-running-the-tcsh-shell dir=”ltr”}

setenv PATH “/homes/USERNAME/binaries/lejos_nxj/bin:$PATH”
setenv LD_LIBRARY_PATH “/homes/USERNAME/binaries/lejos_nxj/bin”
setenv NXJ_HOME “/homes/USERNAME/binaries/lejos_nxj”
setenv JAVA_HOME “/usr”

Check out SVN repository into Eclipse workspace {#check-out-svn-repository-into-eclipse-workspace dir=”ltr”}

  1. File > Import
  2. SVN > Checkout Projects from SVN
  3. Create a new repository location
  4. Enter repository URL
  5. Select trunk
  6. “Check out as a project configured using the New Project Wizard”
  7. Select “Java Project”
  8. Give it a project name (e.g. “robotics”) and set “Project layout” to “Use project folder as root for sources and class files”
  9. Use project folder as root for sources and class files
  10. “Then select Libraries and then “Add external JARs”. Browse for classes.jar in your lejos_nxj/lib installation and select it. As classes.jar replaces the standard Java run time library, you should remove it by selecting “JRE System Library” and clicking “Remove”. You will now see classes.jar (and not JRE System Library) under “Referenced Libraries” in” (source)

Creating new files and packages {#creating-new-files-and-packages dir=”ltr”}

Create a new package for each sub-question.  e.g.


package practicals.p2.q2_3; // practical 2, question 2, part 3


Create a new file inside a new / existing package by right-clicking on the package and selecting New > Class.  Once you’ve created a new class, convert it to a leJOS file by right-clicking on the file and selecting “leJOS NXJ” > “Convert to leJOS NXJ project”.  Right-click again on your robotics folder in Eclipse and select “Properties > Java Build Path > Order and Export” and make sure the JRE library is below the lejos_nxj/lib/classes.jar.

Add the following text immediately below the package line to you .java file:


import lejos.nxt.*;

import fritzlib.*;

Compile and upload to robot {#compile-and-upload-to-robot dir=”ltr”}







nxj practicals.p2.q2_3.SonarDisplay –classpath /home/USERNAME/workspace/robotics –verbose


(given that some of the team want to work on Eclipse and some in Emacs then we may be better off using Ant files to configure classpaths etc, as per these instructions on the leJOS website)

Other useful flags for nxj

  • -u (upload by USB)
  • -b (upload by Bluetooth).
  • -r to automatically run the program after transferring to robot.