Related to MAKE 06, Soccer-Playing Robot

Lejos

May 08, 2006

Here's the quick overview for configuring NetBeans with LeJOS. Keep in mind that I'm using OS X -- some menus may be slightly different for other platforms.

There are two basic steps: 1) configuring NetBeans to do code completion with LeJOS API calls and 2) configuring LeJOS to use lejosc as the compiler for code targets that will be uploaded to the RCX brick.

Code completion

  1. Go to the Tools -> Library Manager window.
  2. Click "New Library..."
  3. Name the new library LeJOS
  4. Click on the newly added libary (LeJOS) in the "Libraries" pane to select it
  5. Click on the "Add JAR/Folder..." button and navigate to the location of $LEJOS_HOME/lib (where you installed LeJOS)
  6. Add the following 4 files one at a time: classes.jar, jtools.jar, pcrcxcomm.jar, rcxrcxcomm.jar
  7. Right click on your project properties for the "RCXServer" portion of the project and add the LeJOS library as a compile-time library
Image Image

Configuring NetBeans to use lejosc

lejosc is the compiler that takes the java source code and turns it into code that the RCX brick can run (whereas javac would compile the source into Java byte code.)

In your folder where you store the code for the RCXServer (the code that runs on the RCX itself -- not the code that runs on your computer) there is a folder called "nbproject" that contains project specific settings. Navigate to this folder and open the file "project.properties"

Find the line in the file starting with "javac.executable=" and change this line to reflect the location of lejosc. i.e. something like javac.executable=/Users/matthew/lejos_2_1_0/bin/lejosc

Find the line in the file starting with "javac.classpath=" and change this line to reflect the location of your LeJOS libraries i.e. javac.classpath= ${libs.LeJOS.classpath}

Note that you only want to use lejosc to compile the portion of your code that runs on the RCX -- not other code that runs on your computer. Thus, you'll only make this modification for the portion of the code that's distributed with the project entitled "RCXServer".

If you have problems, remember that you can always use "lejosc" from the command line.

Regardless of how you do your compile using lejosc, you'll still need to manually use the command line utility "lejos" to upload your newly compiled firmware to the RCX brick (although you could potentially rig up a script to do this for you too if you like.)

Other things to remember about your environment

  • Set a $LEJOS_HOME environment variable to simplify configuration. i.e. LEJOS_HOME=/Users/matthew/lejos_2_1_0
  • Add LeJOS jar files to your $CLASSPATH
  • You may need to add $LEJOS_HOME/bin to your PATH and DYLD_LIBRARY_PATH

If it helps, I have a working configuration and here's the output I get from the command "env | grep -i lejos". You may find it useful for checking your own configuration. (Note that it contains more settings than just the LeJOS specific ones.)

Goliath:~/lejos_2_1_0/bin matthew$ env | grep -i lejos
PATH=/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/
		usr/X11R6/bin:/opt/local/bin:/Users/
		matthew/Library/jython-2.1:/usr/local/
		mysql/bin:/Users/matthew/lejos_2_1_0/bin
PWD=/Users/matthew/lejos_2_1_0/bin
DYLD_LIBRARY_PATH=:/Users/matthew/lejos_2_1_0/bin
LEJOS_HOME=/Users/matthew/lejos_2_1_0
CLASSPATH=.:../:/Library/Java/jmf.jar:/Library/Java/
		customizer.jar:/System/Library/Java/
		Extensions/QTJava.zip:/Library/Java/
		jogl.jar:/Library/Java/jogl-natives-macosx.jar:/
		Users/matthew/lejos_2_1_0/lib/classes.jar:/
		Users/matthew/lejos_2_1_0/lib/jtools.jar:/
		Users/matthew/lejos_2_1_0/lib/pcrcxcomm.jar:/
		Users/matthew/lejos_2_1_0/lib/rcxrcxcomm.jar
Goliath:~/lejos_2_1_0/bin matthew$

Remember that you can always turn to the LeJOS or NetBeans mailing lists for help.