Other programming languages for the leJOS JVM

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Other programming languages for the leJOS JVM

Postby bbagnall » Wed Jun 17, 2009 6:52 pm

NXJ is a JVM just like any other JVM, so it can run pretty much any Java byte code as long as we have the right classes in our class library (the classes.jar file).

Here is a list of programming languages that can run in a JVM:

If you want to try one out, the instructions for getting NetRexx code to compile and run on the NXT brick are:
1. Download NetRexx from the library section:
2. Unzip into a directory. E.g. c:\java\netrexx
3. Add the NetRexxC.jar file in netrexx\lib to your classpath.
4. You probably want the netrexx\bin\NetRexxC in your classpath to use NetRexx.bat to compile code.
5. I also edited a line in NXJ.bat to this:
set NXJ_CP_BOOT=%NXJ_JAR_CLASSES%;c:\java\netrexx\runlib\NetRexxR.jar
(NOTE: Alternately you could edit %NXJ_JAR_CLASSES% to include NetRexxR.jar)
6. Open a text file to enter your NetRexx source code. Call it HelloWorld.nrx.
7. Enter this code:
Code: Select all
import lejos.nxt.

catch InterruptedException

8. To compile, type NetRexxC HelloWorld
9. Now use lejos.bat to link and upload this to your NXT brick.

This example works fine, but if you try a simple example like this you will have an error with the linker:
Code: Select all
say 'Hello World!'

The reason it gives an error is because in order to output text, the NetRexx compiler uses BufferedReader, PrintWriter, and possibly other classes that leJOS NXJ doesn't have in our API:

I'd like to start a project here to do two things:
1. Document which programming languages can be used with the leJOS NXJ JVM, and whether the language allow calls to Java methods like Motor.forward(). Even if the language fails it should be documented so we know there are problems with it.
2. Include instructions for downloading, installing, setting up classpaths and paths, compiling and uploading.
3. Document any limitations/problems with the language under leJOS.
4. Expand the leJOS NXJ API classes to allow more languages to run more completely in the leJOS JVM.

BTW Most of these languages should work fine with the PCComms.jar, because it has access to the full JDK classes. However, the goal is to run these on the actual NXT brick using classes.jar.
Last edited by bbagnall on Wed Jun 17, 2009 7:09 pm, edited 2 times in total.
User avatar
Site Admin
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Basic Compiler

Postby bbagnall » Wed Jun 17, 2009 6:56 pm

Here's some instructions for using a Basic compiler with PCComms.jar. This version of Basic has the ability to access methods in the leJOS API, much like NetRexx. I don't have instructions for leJOS NXJ yet:

1. Download the basic compiler from here:
2. Add the directory to your path (it has Basic.bat) and the jar file in the directory to your classpath.
3. Enter this code in a file called Engine.basic:
Code: Select all
10 NEW motorA, "lejos.nxt.Motor"
20 INVOKE motorA, "forward"

4. Compile the file using:
basic Engine.basic -c
5. Run the program on your PC:
java -classpath pccomm.jar;basic-0.73.jar;. Engine
User avatar
Site Admin
Posts: 392
Joined: Fri Aug 04, 2006 4:03 pm

Return to NXJ Projects

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest

more stuff