Java Compiler & Java Virtual Machine (JVM) on the NSLU2

Being a java developer I was intrigued with the idea of getting a JVM running on my NSLU2, so I looked into how to do this.

Surprisingly it was pretty easy.

To start with you need to install the following packages with ipkg:

ipkg install classpath
ipkg install jamvm
ipkg install jikes
ipkg install zlib
ipkg install file

Once these have installed then you are almost ready to go.  Being a java developer, I was used to using javac and java to compile and execute programs, so jikes and jamvm didn’t sit well with me!  To get around this I created a symbolic link and a shell script in /opt/bin

These are as follows:

/opt/bin/java

 ln -s /opt/bin/jamvm /opt/bin/java

/opt/bin/javac

/opt/bin/jikes -classpath /opt/share/jamvm/classes.zip:/opt/share/classpath/glibj.zip $*

Remember to change the permissions on the shells scripts to add the execute flag!

Having  done all that, I can now create a java file:

HelloWorld.java

class HelloWorld
{
     public static void main(String[] args)
     {
          System.out.println("Pembo's Hello World!");
          System.out.println("Args Length: " + args.length);
          for(int i=0;i<args.length;i++)
          {
               System.out.println("[" + i + "] - " + args[i]);
          }
     }
}

compile this using the command

javac HelloWorld.java

and then run this using the command

java HelloWord test1 test2 test3

And I see the following output:

Pembo's Hello World!
Args Length: 4
[0] - test1
[1] - test2
[2] - test3

JamVM is excellent from what I’ve seen so far and is perfect for Java NSLU2 development.
I’ve yet to run anything overly complex on the Slug so I can’t comment on the memory utilisation.

It takes around a second to compile the above HelloWorld program on the NSLU2 and under a second to run it.

3 thoughts on “Java Compiler & Java Virtual Machine (JVM) on the NSLU2

  1. Hi! I was happy to have found your article, as I also wanted to be able to compile and run Java programs on my NSLU2 (with SlugOS 3.10). Unfortunately, after installing all the above packages, when trying to run jamvm, I am getting the following error message:

    “ld.so does not support TLS, but program uses it!”

    Any suggestions?

    Thanks!
    -J

  2. hi,
    I installed jamvm via IPKG on my slug. I also installed Jikes out of the same IPKG.
    compiled my hello world program and tried running it, but unfortunately I get the error message:
    segmentation fault (core dumped).
    does anybody have an idea on how to solve this?

    I did install all the additional packages too!

Leave a Reply

Your email address will not be published. Required fields are marked *