Eclipse with SVN and NXJ
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)
- Help > Install New Software
- Enter this URL: http://subclipse.tigris.org/update_1.6.x
- Add Subclipse
- Once Subclipse is installed, you’ll also need to install the javaHL library
Install leJOS NXJ plugin for Eclipse
http://lejos.sourceforge.net/nxt/nxj/tutorial/Preliminaries/UsingEclipse.htm
Eclipse configuration
Making Eclipse indent code in an Emacs-compatible way (so other team members can continue to use Emacs)
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
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: http://lejos.sourceforge.net/nxt/nxj/api/
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)
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
- File > Import
- SVN > Checkout Projects from SVN
- Create a new repository location
- Enter repository URL
- Select trunk
- “Check out as a project configured using the New Project Wizard”
- Select “Java Project”
- Give it a project name (e.g. “robotics") and set “Project layout” to “Use project folder as root for sources and class files”
- Use project folder as root for sources and class files
- “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 org.me.myproject.” (source)
Creating new files and packages
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
Run:
nxj PACKAGE.CLASSNAME --classpath /PATH/TO/ROBOTICS --verbose
e.g.:
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.
Add new comment