Skip to main content

Starting with Sun SPOT using NetBeans 6.1

Posted by brunogh on April 11, 2008 at 9:41 PM PDT

If you do not have a Sun SPOT (Figure 1), do not be bored, you can still have a lot of fun! In this entry, I gonna explain how to start programming the world using NetBeans 6.1!


Figure 1: Sun SPOT rulez!!!

Downloading NetBeans IDE 6.1

1. Download NetBeans IDE 6.1 (RC1 launched today). A lot of new nice features, take a look in the New and Noteworthy and in the release page for a detailed list.

Installing Sun SPOT plugin

2. Install Sun SPOT plugin into NetBeans. Download com-sun-sunspot-updatecenter.nbm. Now, in NetBeans, go to:
2.1 Tools menu -> Plugin.
2.2 Click on Downloaded tab.
2.3 Click on Add Plugins button and select the file. Then, confirm the installation clicking on Install button and accept the license agreement.
2.4 Finally, go to the Available Plugins tab, mark SunSPOTApplicationTemplate, SunSPOTHostApplicationTemplate and Sun SPOT Info, click on Install button and accept the license agreement.
2.5 You can check that everything is installed going to Installed tab (Figure 2).

PS: David Simmons has blogged about these steps before.

Figure 2: Installed tab.

Getting Sun SPOT SDK 3.0 Beta

3. Get the Sun SPOT SDK 3.0 Beta emailing David Simmons, more details here. You will receive a link to download SPOTManager tool, that is a jar that installs the SDK and can run the emulator. Be sure you have at least JDK 1.5 and at least Ant 1.6.5 installed and configured in your system.

Creating the Demo Application

4. Let's make the default demo application work. Go to:
4.1 File menu -> New Project
4.2 Select Java category, select Sun SPOT project and then click Next.
4.3 Leave the default project name and package and click Finish.
4.4 Open You can see it extends MIDlet and already has some code. If you are familiar with Java ME, you will not have big problems. But, basically, Sun SPOT arquitecture is CLDC (Connected Limited Device Profile) 1.1 and has IMP (Information Module Profile) in the top - which can be defined as a MIDP (Mobile Information Device Profile) without UI stuff. Also, it has some additional libraries and all this runs in a VM called Squawk, that is characterized by being most written in Java. So, StartApplication implements the abstract methods inherited from the MIDlet (startApp,pauseApp that Squawk never calls and destroyApp). It works in a sand box enviromnent.

The startApp code, in List 1, basically gets an object reference to the singleton eDemo Board and then make its LED blink red for a quarter of second each second. As you, can see, the code is pretty high level and easy to understand.

    protected void startApp() throws MIDletStateChangeException {
        System.out.println("Hello, world");
        new BootloaderListener().start();   // monitor the USB (if connected) and recognize commands from host

        long ourAddr = Spot.getInstance().getRadioPolicyManager().getIEEEAddress();
        System.out.println("Our radio address = " + IEEEAddress.toDottedHex(ourAddr));

        ISwitch sw1 = EDemoBoard.getInstance().getSwitches()[EDemoBoard.SW1];
        leds[0].setRGB(100,0,0);                // set color to moderate red
        while (sw1.isOpen()) {                  // done when switch is pressed
            leds[0].setOn();                    // Blink LED
            Utils.sleep(250);                   // wait 1/4 seconds
            Utils.sleep(1000);                  // wait 1 second
        notifyDestroyed();                      // cause the MIDlet to exit

List 1: startApp code.

Running the Demo Application in the emulator

5. Put this application to run in the emulator.
5.1 Right click the project and select Build. It will generate the jar in the /$PROJECT_HOME/suite/. If you have a spot device, you could send it directly by right clicking the project and selecting Build Project + Deploy to Sun SPOT , forgetting the next steps.
5.2 Open the emulator (in the ToolManager, go to Solarium tab and then click in the Solarium button). Then, in the emulator, click on the Emulator menu -> New virtual SPOT, you will notice that a Sun SPOT will appear in the squared right area.
5.3 Right click on the Sun SPOT picture, then click Specify application jar file... and select the application jar in /$PROJECT_HOME/suite/, which is the place that the application was built in step 5.1.
5.4 After that, click again on it, then Run MIDlet and StartApplication. Finally, you will see a red LED blinking!!! Wow!


Figure 3: NetBeans 6.1, ToolManager, Emulator and the red LED blinking!

Where I go next?

In NetBeans, check the Sun SPOT Info, that you have installed with the plugin, by clicking in the Window menu.
David Simmons' Blog -
Roger Meike's Blog -
Sun SPOT Feeds (really nice aggregator with more cool blogs) -
Project Sun SPOT -
Open source Sun SPOT - (take a look in its subprojects as well).
Search for spaughts in or subscribe the tag feed directly.
Recently, Aaron Houston has organized a conference call about Sun SPOT with Roger Meike and published the nice links we get during it in an email he sent. The links are available here too. Slides here.

PS: I am using this entry for the NetBeans IDE 6.1 Beta Blogging Contest, take a look at for more information about it. Go ahead, make an entry and have a chance to win $500! Good luck for us!


Thanks! Have a nice weekend!

Program the world!

Bruno Ghisi

Related Topics >>


I have a problem running SPOTs' Emulator. I have tried almost everything that I have read in the blogs, but still I am getting the same error: Buildfile: C:\Sun\SunSPOT\sdk\build.xml -pre-init: -do-init: -post-init: init: -set-basestation-not-required: -set-selector-for-host-run: -override-warning-find-spots: -prepare-conditions-for-find-spots: -find-shared-basestation: -run-spotfinder: -decide-whether-to-run-spotselector: -run-spotselector: -collect-spotselector-result: -clean-up-spotselector-output-file: -spotselector-fail: -decide-whether-to-start-basestation-manager: -start-new-basestation-manager: -do-find-spots: -do-run-spotworld: [echo] Java Runtime Environment version: 1.6.0_06 [java] Port dummyport unavailable... retrying... [java] [Emulator System.err] Cannot load C:\Program Files\Java\jdk1.6.0_06\jre\bin\server [java] [Emulator System.err] Please add the directory containing jvm.dll to your PATH [java] [Emulator System.err] environment variable or set the JVMDLL environment variable [java] [Emulator System.err] to the full path of this file. [java] [Emulator System.err] Warning: Error creating Java VM -- I/O subsystem will be disabled [java] [Emulator System.err] Uncaught exception in [java] [Emulator System.err] on thread - main [java] [Emulator System.err] java.lang.Error: IO error while loading suite from 'file://C:/Sun/SunSPOT/sdk\lib\emulator.suite': no native I/O peer for isolate [java] [Emulator System.err] at java.lang.Throwable.(bci=16) [java] [Emulator System.err] at java.lang.Throwable.(bci=5) [java] [Emulator System.err] at java.lang.Error.(bci=6) [java] [Emulator System.err] in static method #3 of com.sun.squawk.Suite(bci=72) [java] [Emulator System.err] in static method #4 of com.sun.squawk.Suite(bci=6) [java] [Emulator System.err] in virtual method #40 of com.sun.squawk.Isolate(bci=41) [java] [Emulator System.err] at [java] [Emulator System.err] at [java] [Emulator System.err] in virtual method #47 of com.sun.squawk.VMThread(bci=38) [java] [Emulator System.err] in static method #3 of com.sun.squawk.VM(bci=6) [java] [Emulator System.err] [java] [Emulator System.err] [java] [Emulator System.err] -------------------------------------------------------------------- [java] [Emulator System.err] Hits - Class:93.10% Monitor:90.23% Exit:100.00% New:99.86% [java] [Emulator System.err] GCs: 0 full, 0 partial [java] [Emulator System.err] ** VM stopped: exit code = 1 ** [java] Port dummyport unavailable... retrying... [java] Port dummyport unavailable... retrying... [java] Port dummyport unavailable... retrying... [java] Port dummyport unavailable... retrying... [java] Available ports: COM1 COM2 LPT1 [java] Error connecting to Squawk VM: Accept timed out [java] Error: connection to Squawk VM was never established. Cannot run MIDlets on virtual SPOT [java] Error: connection to Squawk VM was never established. Cannot run MIDlets on virtual SPOT spotworld: BUILD SUCCESSFUL Total time: 2 minutes 2 seconds Can you help me to solve the problem? Thanks,Sandra

Hello! Try to post this error on SunSPotWorld Forum too (, maybe more people can help. Thanks.

thanks a lot ! I am first use this software.installing is OK!but Emulator does't not work>"Error: connection to Squawk VM was never established. Cannot run MIDlets on virtual SPOT"this comment exists when I run Emulator ,how to solve this problem.thank you again.

Nice post. Nice tutorial. Well done!!! Blogged here


Hello Sandra, I am not sure about your problem, maybe you should try the forum ( Thanks.