Getting Started on Microsoft Windows
This version of the tutorial is for the 0.9 release of leJOS NXJ.
Java Development Kit
You will also need a Java Development Kit (JDK) on your PC. Note that a Java Runtime Environment (JRE) is not sufficient as it does not allow you to compile Java programs. You can download the latest JDK from http://www.oracle.com/technetwork/java/javase/downloads/. Follow the instructions for installing it. leJOS NXJ has been tested with JDK versions 1.5, 1.6, and 1.7, and will not work with earlier versions. JDK 1.6 or 1.7 is recommended.
leJOS NXJ only works with 32-bit version of the JDK and JRE, so even if you have a 64-bit system, you should select a 32-bit version of the JDK.
To run leJOS NXJ on Microsoft Windows you will need a suitable USB driver on your PC. If you have installed the standard LEGO Mindstorms NXT-G software, a suitable driver (the so-called Fantom driver) is already installed. If you do not wish to install the LEGO software on your PC or if you want to update the Fantom driver to the latest version, you can get an installer from The LEGO Mindstorms site. It is strongly recommended to update to the latest version (1.1.3 at the time of writing).
It has come to our attention, that NXT-G as well as the Fantom driver don't install under Windows 7 Starter Edition.
This can be worked around by adding a line to the setup.ini file.
Here you find the official instructions
by National Instruments, the authors of NXT-G and the Fantom driver. In short, you have to add
If you want to communicate with the NXT over Bluetooth, you will need a Bluetooth dongle or built-in support on your PC, and a Bluetooth software stack. leJOS NXJ has been tested with the Microsoft and Widcomm stacks, but might also work with others. Bluesoleil is known to cause problems. You can use leJOS NXJ without Bluetooth.
Downloading the software
You can download the leJOS NXJ software from The leJOS NXJ download page.
It is recommended that you use the Windows installer, but there is a ZIP file release that you can use if you prefer to do a manual installation.
Running the GUI installer
Click "Next". Note, that at this point the installer will check whether the installed fantom driver is up-to-date. The installer will report an error if that is not the case and you can chose whether the open the Fantom driver download page or to continue without installing or updating the Fantom driver. In the latter case, USB communication with the NXT might not work properly. If the installation continues, you will see the next page of the installer:
This page asks you to select the root folder of a 32 Bit Java Development Kit (JDK). You cannot continue the installation process without doing so. If none is installed, click the Download JDK button, download and installa a 32 Bit JDK and restart the installer. The selected folder will be assigned to the LEJOS_NXT_JAVA_HOME environment variable automatically at the end of the installation process.
The next step is to select the destination directory, in which leJOS will be installed:
You can change the destination if you need to. Click on the "Browse" button to change the destination. On the next page, you can chose which components to install:
It is usually not necessary to modify these. However, you may chose to omit the documentation (it is also available online) or you may chose to install any of the additional sources. The Sample and Example Projects are also contained in the samples.zip that is part of the leJOS Development Kit. The Sources of the leJOS Development Kit can be used to modify and rebuild leJOS it self. It is usually not needed, if you only plan on developing programs based on leJOS and do not plan to modify components of leJOS itself. All additional sources are also available as a seperate download. If any additional sources have been selected, the destination directories for them can be changed on the next page.
Note, that this page is skipped if no additional sources have been selected. The next page allows to adjust the folder in the start menu, that the leJOS shortcuts will be installed to:
The next page shows a summary of your choices:
The installation will start, if you click "Install". Note, that at this point the installer checks for any previous installs of leJOS. If any are found, their uninstaller is started. You cannot proceed with the installation without uninstalling the previous version.
After the installation complete, the following page will appear:
Uncheck "Launch NXJ Flash utility" if you don't want to start the graphical version of nxjflash, which allows you to upload the leJOS firmware onto the NXT brick. The leJOS firmware is needed to run any Java programs on the NXT. So it is recommened to run nxjflash. Note, that it is possible to revert to the original Lego firmware later.
If you chose to NXJ Flash, you will see:
Click "Start Program" and you will be asked:
Click OK and you will be asked:
If you select "Yes" all current files on the NXT are erased. It is a good idea to select this as old .nxj files may not work with the new firmware.
You will then see:
Make sure that your NXT is connected to the PC by the USB cable and witched on. Then press "OK" and you should see some progess messages, such as:
When your NXT has been updated, you will be asked:
If you have more NXTs to update, click "Yes". When you have finished click "No" and the flash utility will terminate and then the installer will terminate, and you are done.
Skip to the section below on testing your installation.
If you have been using the GUI installer, skip this section and go to "Testing the Installation". This section described the manual install without the GUI installer.
Downloading and Unzipping
Download the file called
Setting up environment variables
leJOS NXJ needs to know the locations of java.exe and javac.exe. There are several possibilities
to achieve that: (1) add the bin directory of the JDK to your PATH environment variable
so that commands such as
Furthermore, the NXJ_HOME variable should be set to the directory where leJOS NXJ is installed. It allows other applications, e.g. the Ant scripts, to locate the leJOS Development Kit. Also, for easy exececution of the leJOS commands on the command line, the bin folder of the leJOS distribution should be added to the PATH variable.
The Windows installer will automatically sets all three environment variables for you. Setting them manually is only required during manual installation. You can set these environment variables manually by going to Control Panel > System > Advanced > Environment Variables and creating them or editing existing values. You can set them either as user or system variables depending on whether you want leJOS NXJ to be available to all users or just the current user.
Using a Command Window
You will need to run command-line commands to test your installation and optionally to flash the firmware. If you plan to use IDE such as Eclipse or Netbeans, once you have installed your IDE, you should not need to use the command window any more.
You can start a command window on Windows XP by Start > Run and typing cmd. On Vista or Windows 7, type "Command Prompt".
Flashing the Firmware
As leJOS NXJ is a firmware replacement, you will need to flash the firmware to your NXT. Note that this will overwrite any existing firmware. If you have the standard LEGO firmware or other third-party firmware on your NXT, existing files will be lost. However, it is possible to revert to the original Lego firmware either by using the Software provided by Lego or by using nxjflash.
The 0.9.0 release increases the amount of flash memory used by the firmware and the startup menu, so the first time you flash this version of the firmware, existing leJOS NXJ files will be deleted.
Make sure your NXT is attached to the PC via USB cable and switch it on by pressing the orange button.
Open a command line prompt (as described above) and either type the command
If you chose
If you chose
Testing your Installation
You can test your installation by following the steps for writing your first leJOS Program which are the next part of this tutorial.