如果找到了对您有用的资料,烦请点击右手边的Google广告支持我继续共享知识,谢谢! http://dengpeng.spaces.live.com/

2008年7月17日星期四

Simple JAXB Application

Java Architecture for XML Binding (JAXB) allows Java developers to map Java classes to XML representations. JAXB provides two main features: the ability to marshal Java objects into XML and the inverse, i.e. to unmarshal XML back into Java objects. In other words, JAXB allows storing and retrieving data in memory in any XML format, without the need to implement a specific set of XML loading and saving routines for the program's class structure.

JAXB is particularly useful when the specification is complex and changing. In such a case, regularly changing the XML Schema definitions to keep them synchronised with the Java definitions can be time consuming and error prone.

The tool "xjc" can be used to convert XML Schema and other schema file types (as of Java 1.6, RELAX NG and XML DTDs are supported experimentally) to class representations. Classes are marked up using annotations from javax.xml.bind.annotation.* namespace, for example, @XmlRootElement and @XmlElement. XML list sequences are represented by attributes of type java.util.List. Marshallers and Unmarshallers are created through an instance of JAXBContext.

In addition, JAXB includes a "schemagen" tool which can essentially perform the inverse of "xjc", creating an XML Schema from a set of annotated classes.

--http://en.wikipedia.org/wiki/JAXB

country.xsd

<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="country" type="Country"/>
<xs:complexType name="Country">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="population" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:schema>





country.xml


<country
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="country.xsd">
<name>France</name>
<population>60144000</population>
</country>





1. Download JAXB from https://jaxb.dev.java.net/


2. Convert XML schema to Java class source file. The command is xjc.bat -package.name sourceXMLSchema.xsd. For example, execute xjc.bat –countries country.xsd, we should get these files:



  • Country.java


  • ObjectFactory.java



3. Create a project in Netbeans, and copy the generated source files to the folder of project source. And do not forget to add the JAXB 2.1 library in project properties.


4. Here below is the source code of main java which shows both read and write XML functions:


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package simplejaxb;

import countries.Country;
import countries.ObjectFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.math.BigDecimal;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
// Read and convert a XML file from disk to a Java object in memory
readAndConvert("country.xml");

// Write a Java object in memory to a XML file on disk
writeXML("country2.xml");
}

private static void readAndConvert(String path) {
try {
// Read XML to Java object
JAXBContext jc = JAXBContext.newInstance("countries");
Unmarshaller um = jc.createUnmarshaller();
JAXBElement<Country> countryElement = (JAXBElement<Country>) um.unmarshal(new File(path));
Country c = countryElement.getValue();

//Print out values from Java object
System.out.println(c.getName());
System.out.println(c.getPopulation());
} catch (JAXBException ex) {
ex.printStackTrace();
}
}

private static void writeXML(String path) {
try {
// Create java object and assign values to this object
JAXBContext jaxbContext = JAXBContext.newInstance("countries");
ObjectFactory objFactory = new ObjectFactory();
Country c = objFactory.createCountry();
c.setName("China");
c.setPopulation(BigDecimal.valueOf(130000000));
JAXBElement<Country> countryElement = objFactory.createCountry(c);

// Create instance of marshaller and write object to XML file
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
marshaller.marshal(countryElement, new FileOutputStream(path));
} catch (Exception ex) {
ex.printStackTrace();
}

}
}


5. if you still confuse about how the app works, you can douload the project archieve from http://www.mediafire.com/?zpt74jm5gs2








This is another example which is a bit complex than the one above. We have XML Schema file and a XML file.



books.xsd



<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="1.0">


<xs:element name="Collection">
<xs:complexType>
<xs:sequence>
<xs:element name ="books">
<xs:complexType>
<xs:sequence>
<xs:element name="book" type="bookType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>

<xs:complexType name="bookType">
<xs:sequence>
<xs:element name="name" type="xs:string"/>
<xs:element name="ISBN" type="xs:long"/>
<xs:element name="price" type="xs:string"/>
<xs:element name="authors" >
<xs:complexType>
<xs:sequence>
<xs:element name="authorName" type="xs:string" minOccurs="1"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="promotion">
<xs:complexType>
<xs:choice>
<xs:element name="Discount" type="xs:string" />
<xs:element name="None" type="xs:string"/>
</xs:choice>
</xs:complexType>
</xs:element>
<xs:element name="publicationDate" type="xs:date"/>
<xs:element name="bookCategory">
<xs:simpleType>
<xs:restriction base="xs:NCName">
<xs:enumeration value="magazine" />
<xs:enumeration value="novel" />
<xs:enumeration value="fiction" />
<xs:enumeration value="other" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
<xs:attribute name="itemId" type="xs:string" />
</xs:complexType>



<xs:simpleType name="bookCategoryType" >
<xs:restriction base="xs:string">
<xs:enumeration value="magazine" />
<xs:enumeration value="novel" />
<xs:enumeration value="fiction" />
<xs:enumeration value="other" />
</xs:restriction>
</xs:simpleType>


</xs:schema>





books.xml



<?xml version="1.0"?>
<Collection>
<books>
<book itemId="999">
<name>
Learning JAXB
</name>
<ISBN>
123445
</ISBN>
<price>
34 $
</price>
<authors>
<authorName> Jane Doe
</authorName>
</authors>
<description>
This books contains step by step instructions for beginners so that they can start using Java API for XML Binding.
</description>
<promotion>
<Discount> 10% on this book if purchased by March 2003
</Discount>
</promotion>
<publicationDate>
2003-01-01
</publicationDate>
<bookCategory>other
</bookCategory>
</book>

<book itemId="129">
<name>
Java Webservices today and Beyond
</name>
<ISBN>
522965
</ISBN>
<price>
29 $
</price>
<authors>
<authorName> John Brown
</authorName>
<authorName> Peter T.
</authorName>
</authors>
<description>
This books contains information for users so that they can start using Java Web Services Developer Pack.
</description>
<promotion>
<Discount> Buy one get Learning webservices Part 1 free
</Discount>
</promotion>
<publicationDate>
2002-11-01
</publicationDate>
<bookCategory>magazine
</bookCategory>
</book>
</books>
</Collection>




Follow the same first three steps of previous example. Here below is the source of main.java to read and output a XML file:



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package hellojaxb;

import books.BookType;
import books.Collection;
import books.Collection.Books;
import books.ObjectFactory;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
// Read and convert a XML file from disk to a Java object in memory
readAndConvert("books.xml");

// Write a Java object in memory to a XML file on disk
writeXML("jaxbOutput2.xml");
}

private static void readAndConvert(String path) {
try {
// Read XML to Java object
JAXBContext jc = JAXBContext.newInstance("books");
Unmarshaller um = jc.createUnmarshaller();
Collection col = (Collection) um.unmarshal(new File(path));
Books bt = col.getBooks();
List bl = bt.getBook();

//Print out values from Java object
BookType book = (BookType) bl.get(0);
System.out.println(book.getName());
} catch (JAXBException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}

private static void writeXML(String path) {
try {
// Create java object and assign values to this object
JAXBContext jaxbContext = JAXBContext.newInstance("books");
ObjectFactory objFactory = new ObjectFactory();
Collection collection = (Collection) objFactory.createCollection();
Books booksType = objFactory.createCollectionBooks();
List bookList = booksType.getBook();

// Create one instance of book
BookType book = objFactory.createBookType();
book.setItemId("307");
book.setName("JAXB today and beyond");
book.setDescription("This is an intermediate book on JAXB");
book.setISBN(987665L);
book.setPrice("45$");
//book.setPublicationDate();
book.setBookCategory("other");
BookType.Promotion promotionType = objFactory.createBookTypePromotion();
promotionType.setDiscount("5% off regular price");
book.setPromotion(promotionType);
BookType.Authors authorsType = objFactory.createBookTypeAuthors();
List authorList = authorsType.getAuthorName();
authorList.add("Richard K");
book.setAuthors(authorsType);

bookList.add(book);
collection.setBooks(booksType);

// Create instance of marshaller and write object to XML file
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true));
marshaller.marshal(collection, new FileOutputStream(path));
} catch (Exception ex) {
ex.printStackTrace();
}
}
}


5. if you still confuse about how the app works, you can douload the project archieve from http://www.mediafire.com/?vm5gy2xrcjd

2008年7月16日星期三

Identify the COM port number and device address of Sun SPOT

Basically, I am using the spotfinder.exe which is a tool provided with Sun SPOT SDK to detect the COM port in use and device adddress of the connected Sun SPOT.
NOTE: Only one SPOT can be detected in this, I would like to change it later.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package simpleexec;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
// TODO code application logic here
int portNumber = spotCOMPort();
System.out.println(portNumber);
String deviceMACAddress = getDeviceMACAddress();
System.out.println(deviceMACAddress);
}

private static String getDeviceMACAddress() {
try {
String rawString = "";
String line;
Process p = Runtime.getRuntime().exec("C:\\Program Files\\Sun\\SunSPOT\\sdk\\bin\\spotfinder.exe -vv");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
rawString = rawString + line;
}
input.close();
String rawAddress = String.valueOf(rawString.subSequence(rawString.indexOf("00144F01") + 8, rawString.indexOf("00144F01") + 16));
String MACAddress = "0014.4F01." + rawAddress.substring(0, 4) + "." + rawAddress.substring(4, 8);
return MACAddress;
} catch (Exception err) {
err.printStackTrace();
return "-1";
}
}

private static int spotCOMPort() {
try {
String rawString = "";
String line;
Process p = Runtime.getRuntime().exec("C:\\Program Files\\Sun\\SunSPOT\\sdk\\bin\\spotfinder.exe -vv");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
rawString = rawString + line;
//System.out.println(line);
}
input.close();
String comPort = String.valueOf(rawString.subSequence(rawString.indexOf("(COM") + 4, rawString.indexOf(")parsed")));
return Integer.parseInt(comPort);
} catch (Exception err) {
err.printStackTrace();
return -1;
}
}
}

Run SPOT Host application without ant 2

This blog is a supplementary of previous entry: http://pauldeng.blogspot.com/2008/03/run-spot-host-application-without-ant.html

1. Execute ant host-run –v, you should get the print out similar to text below:
Apache Ant version 1.7.1 compiled on June 27 2008
Buildfile: build.xml
Detected Java version: 1.5 in: C:\Program Files\Java\jdk1.5.0_16\jre
Detected OS: Windows XP
parsing buildfile C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/build.xml
Project base dir set to: C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop
[antlib:org.apache.tools.ant] Could not load definitions from resource org/apache/tools/ant/antlib.xml. It could not be found.
[property] Loading C:\Documents and Settings\tkob\.sunspot.properties
Importing file C:\Program Files\Sun\SunSPOT\sdk\build.xml from C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\build.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/build.xml
[property] Loading C:\Documents and Settings\tkob\.sunspot.properties
Override ignored for property "spotselector.basestation.lastport"
Override ignored for property "sunspot.lib"
Override ignored for property "spot.library.name"
Override ignored for property "sunspot.home"
parsing buildfile jar:file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/ant-contrib.jar!/net/sf/antcontrib/antlib.xml with URI = jar:file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/ant-contrib.jar!/net/sf/antcontrib/antlib.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\clean.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\clean.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/clean.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\compile.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\compile.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/compile.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/find-spots.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\sysadmin.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\sysadmin.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/sysadmin.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\run-spotclient.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\run-spotclient.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/run-spotclient.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml from C:\Program Files\Sun\SunSPOT\sdk\ant\run-spotclient.xml
Skipped already imported file:
C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml

Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\echo.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\echo.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/echo.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml from C:\Program Files\Sun\SunSPOT\sdk\ant\echo.xml
Skipped already imported file:
C:\Program Files\Sun\SunSPOT\sdk\ant\find-spots.xml

Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\debug-proxy.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\debug-proxy.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/debug-proxy.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\deploy.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\deploy.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/deploy.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml from C:\Program Files\Sun\SunSPOT\sdk\ant\deploy.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/jar-app.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\help.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\help.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/help.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\host-compile.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\host-compile.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/host-compile.xml
Already defined in main or a previous import, ignore -post-host-compile
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\host-run.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\host-run.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/host-run.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\init.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\init.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/init.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\library.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\library.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/library.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\preverify.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\preverify.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/preverify.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\run.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\run.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/run.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\suite.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\suite.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/suite.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
Skipped already imported file:
C:\Program Files\Sun\SunSPOT\sdk\ant\jar-app.xml

Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\sdk-info.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\sdk-info.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/sdk-info.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\upgrade.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\upgrade.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/upgrade.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\socket-proxy.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\socket-proxy.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/socket-proxy.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\networktools-run.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\networktools-run.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/networktools-run.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\spotworld.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\spotworld.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/spotworld.xml
Importing file C:\Program Files\Sun\SunSPOT\sdk\ant\spotworldextension.xml from C:\Program Files\Sun\SunSPOT\sdk\build.xml
parsing buildfile C:\Program Files\Sun\SunSPOT\sdk\ant\spotworldextension.xml with URI = file:/C:/Program%20Files/Sun/SunSPOT/sdk/ant/spotworldextension.xml
Build sequence for target(s) `host-run' is [-pre-init, -do-init, -post-init, init, -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, -pre-host-compile, -do-host-compile, -post-host-compile, host-compile, -pre-host-run, -do-host-run, -post-host-run, host-run]
Complete build sequence is [-pre-init, -do-init, -post-init, init, -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, -pre-host-compile, -do-host-compile, -post-host-compile, host-compile, -pre-host-run, -do-host-run, -post-host-run, host-run, -pre-library, -set-properties, -combine-manifests, create-manifest, -do-library-new, -unjar-utility-jar, -pre-compile, -do-compile, -post-compile, compile, preverify.-unjar-utility-jars, library.-combine-manifests, Telemetry-onDesktop.-failIfRemote, library.-append-manifest-contents, deploy.-do-deploy, -find-manifest, -set-jar-name, -check-for-jar, -remote-echo, find-spots.-decide-whether-to-start-basestation-manager, Telemetry-onDesktop.compile, -failIfSerial, getallappsstatus, -do-suite-new, -do-suite-old, suite.-do-suite, hello, run.-pre-run, help.-help, Telemetry-onDesktop.deletepublickey, -do-run, getsleepinfo, Telemetry-onDesktop.selectnothing, -do-debug, debug, Telemetry-onDesktop.debug-run, Telemetry-onDesktop.-set-selector-for-nonbasestation, -check-run-spotclient-parameters, Telemetry-onDesktop.system-properties, run-spotclient.-check-run-spotclient-parameters, jar-app.-pre-jar-app, Telemetry-onDesktop.disableota, -failIfRemote, -do-upgrade, Telemetry-onDesktop.upgrade, compile.-do-compile, -echo-progress-for-local-runs, -post-library, getappstatus, upgrade.-conditionally-deploy-selftest, init.-do-init, jar, SpotWorldExtensions.getallappsstatus, library.-do-library-old, socket-proxy.-set-selector-for-socket-proxy-run, SpotWorldExtensions.startapp, -echo-progress-for-remote-runs, -do-jar-app, deploy.-pre-deploy, startbasestation, suite.-post-suite, compile.-do-compile-single, -set-basestation-sharing, SpotWorldExtensions.stopapp, Telemetry-onDesktop.blink, getsuitemanifest, upgrade.-conditionally-upgrade-pctrlfirmware, find-spots.-run-spotselector, -pre-clean, -do-clean, -post-clean, clean, -pre-preverify, -make-preverify-directory, -unjar-utility-jars, -do-preverify, -post-preverify, preverify, -pre-jar-app, -post-jar-app, jar-app, -pre-suite, -do-suite, -post-suite, Telemetry-onDesktop.suite, preverify.-unjar-utility-jar, -set-selector-for-socket-proxy-run, -pre-socket-proxy-run, -do-socket-proxy-run, -post-socket-proxy-run, Telemetry-onDesktop.socket-proxy, debug-run, -do-debug-proxy-run, -run-spotclient-for-one-remote-id, debug-proxy.-do-debug-proxy-run, spotworldextension-help, socket-proxy, find-spots.-start-new-basestation-manager, resumeapp, delete-system-property, info, Telemetry-onDesktop.slots, Telemetry-onDesktop.settime, javadoc, run-spotclient.-echo-progress-for-local-runs, -pre-debug-proxy-run, -post-debug-proxy-run, Telemetry-onDesktop.debug-proxy, Telemetry-onDesktop.make-host-jar, selectnothing, sysadmin.-pre-sysadmin, disableota, run.-post-run, sysadmin.-post-sysadmin, SpotWorldExtensions.getsuitemanifest, -set-selector-for-nonbasestation, Telemetry-onDesktop.host-run, host-compile.-do-host-compile, -do-networktools-init, suite.-do-suite-old, -run-spotclient-once-with-remote-id, flashconfig, deploy.-post-deploy, echo.-local-echo, -do-library-old, -do-library, library, Telemetry-onDesktop.flashconfig, blink, Telemetry-onDesktop.selectbasestation, host-run.-set-selector-for-host-run, Telemetry-onDesktop.resetfat, selectbasestation, -pre-run, -post-run, run, base, suite, -local-echo, -check-port, echo.-do-echo, -post-sysadmin, Telemetry-onDesktop.library, -do-sdk-info, -pre-sysadmin, -test-ant-version, -unable-to-sysadmin, -really-do-sysadmin, -do-sysadmin, sysadmin, selectdummyapp, jar-app.-do-jar-app, run-spotclient.-run-spotclient-for-one-remote-id, system-properties, -do-deploy, slots, -do-networktools-run, tracert, -do-socket-proxy-gui-run, Telemetry-onDesktop.socket-proxy-gui, SpotWorldExtensions.pauseapp, preverify.-do-preverify, flashbootloader, Telemetry-onDesktop.flashbootloader, run-spotclient.-run-spotclient-once-locally, -post-compile-single, compile.-pre-compile, host-run.-pre-host-run, flashbootstrap, find-spots.-override-warning-find-spots, Telemetry-onDesktop.tracert, -set-flag-for-fork, sdk-info.-do-sdk-info, -pre-compile-single, deletepublickey, Telemetry-onDesktop.selectmeshrouter, SpotWorldExtensions.getpowerstats, -help, run-spotclient.-run-spotclient-once-with-remote-id, host-run.-do-host-run, startapp, Telemetry-onDesktop.debug, find-spots.-run-spotfinder, fork, run.-do-run, debug-proxy.-post-debug-proxy-run, find-spots, host-run.-post-host-run, Telemetry-onDesktop.start-shared-basestation, Telemetry-onDesktop.selectapplication, networktools-run.-do-networktools-run, init.init, suite.-pre-suite, clean.-pre-clean, Telemetry-onDesktop.resetlibrary, Telemetry-onDesktop.preverify, -do-compile-single, socket-proxy.-do-socket-proxy-run, upgrade.-conditionally-upgrade-demosensorboardfirmware, echo.-remote-echo, help, SpotWorldExtensions.spotworldextension-help, preverify.-make-preverify-directory, -conditionally-deploy-selftest, library.-post-library, SpotWorldExtensions.resumeapp, debug-proxy, -set-basestation-not-required, -do-run-spotworld, Telemetry-onDesktop.spotworld, find-spots.-decide-whether-to-run-spotselector, -run-spotclient-multiple-times-with-remote-id, -run-spotclient-once-locally, -run-spotclient-multiple-times-locally, -run-spotclient, socket-proxy.-pre-socket-proxy-run, setserialnumber, networktools-run.-do-networktools-init, Telemetry-onDesktop.setserialnumber, Telemetry-onDesktop.selectdummyapp, echo.-check-port, -check-for-manifest, -pre-deploy, -post-deploy, jar-deploy, Telemetry-onDesktop.deploy, socket-proxy-gui, Telemetry-onDesktop.setpublickey, Telemetry-onDesktop.-set-jar-name, -user-help, clean.-do-clean, Telemetry-onDesktop.-set-basestation-sharing, Telemetry-onDesktop.find-spots, SpotWorld.-do-run-spotworld, Telemetry-onDesktop.sysadmin, debug-proxy.-do-debug, run-spotclient.-run-spotclient-multiple-times-locally, pauseapp, find-spots.-collect-spotselector-result, find-spots.-spotselector-fail, setpublickey, Telemetry-onDesktop.host-compile, find-spots.-prepare-conditions-for-find-spots, Telemetry-onDesktop.flashbootstrap, jar-app.-post-jar-app, compile.-post-compile, selectmeshrouter, Telemetry-onDesktop.clean, init.-post-init, jar-app.-find-manifest, sysadmin.-do-sysadmin, Telemetry-onDesktop.enableota, library.-do-library-new, run-spotclient.-echo-progress-for-remote-runs, sysadmin.-really-do-sysadmin, compile.-post-compile-single, stopapp, selectapplication, flashapp, run.-set-flag-for-fork, library.-do-library, Telemetry-onDesktop.fork, flashvm, -do-echo, echo, make-host-jar, start-shared-basestation, library.create-manifest, preverify.-pre-preverify, socket-proxy.-do-socket-proxy-gui-run, library.-set-properties, help.-user-help, Telemetry-onDesktop.flashvm, sysadmin.-test-ant-version, -conditionally-upgrade-pctrlfirmware, getavailablesuites, getmemorystats, upgrade.-do-upgrade, clean.-post-clean, Telemetry-onDesktop.flashlibrary, compile-single, enableota, Telemetry-onDesktop.help, flashlibrary, suite.-do-suite-new, host-compile.-post-host-compile, deploy.-check-for-jar, upgrade, Telemetry-onDesktop.sdk-info, find-spots.-find-shared-basestation, resetlibrary, -append-manifest-contents, Telemetry-onDesktop.jar-deploy, sdk-info, SpotWorldExtensions.getsleepinfo, run-spotclient.-run-spotclient, SpotWorldExtensions.getmemorystats, compile.-pre-compile-single, sysadmin.-unable-to-sysadmin, deploy.-check-for-manifest, run-spotclient.-run-spotclient-once, preverify.-post-preverify, SpotWorldExtensions.getappstatus, Telemetry-onDesktop.set-system-property, find-spots.-do-find-spots, Telemetry-onDesktop.run, Telemetry-onDesktop.delete-system-property, init.-pre-init, socket-proxy.-post-socket-proxy-run, settime, host-compile.-pre-host-compile, Telemetry-onDesktop.info, Telemetry-onDesktop.-set-basestation-not-required, getpowerstats, Telemetry-onDesktop.startbasestation, set-system-property, find-spots.-clean-up-spotselector-output-file, run-spotclient.-run-spotclient-multiple-times-with-remote-id, library.-pre-library, Telemetry-onDesktop.hello, spotworld, Telemetry-onDesktop.flashapp, Telemetry-onDesktop.echo, -run-spotclient-once, Telemetry-onDesktop.jar-app, Telemetry-onDesktop.-failIfSerial, -conditionally-upgrade-demosensorboardfirmware, deploy, resetfat, debug-proxy-run, Telemetry-onDesktop.debug-proxy-run, debug-proxy.-pre-debug-proxy-run, SpotWorldExtensions.getavailablesuites, , Telemetry-onDesktop.compile-single]

-pre-init:

-do-init:
[property] Loading C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build.properties
[property] Loading C:\Program Files\Sun\SunSPOT\sdk\default.properties
Override ignored for property "sunspot.lib"
Override ignored for property "user.import.paths"
Override ignored for property "main.class"
Override ignored for property "host.java.version"
Override ignored for property "spot.library.name"
Override ignored for property "user.properties.file"
[property] Loading Environment env.
[available] Found: C:\Program Files\Java\jdk1.5.0_16\jre\bin\client\jvm.dll
Override ignored for property "do.set.jvmdll"
Override ignored for property "JVMDLL.KEY"
Override ignored for property "JVMDLL.VALUE"
Property "remoteid" has not been set
Property "remoteID" has not been set

-post-init:

init:

-set-selector-for-host-run:

-override-warning-find-spots:
Skipped because property 'port' not set.

-prepare-conditions-for-find-spots:

-find-shared-basestation:
Skipped because property 'spotselector.findsharedbasestation' not set.

-run-spotfinder:
[exec] Current OS is Windows XP
[exec] Error redirected to property: spotfinder.portlist
[exec] Executing 'C:\Program Files\Sun\SunSPOT\sdk\bin\spotfinder'
[exec] The ' characters around the executable and arguments are
[exec] not part of the command.
Property "basestation.not.required" has not been set

-decide-whether-to-run-spotselector:

-run-spotselector:
Override ignored for property "spottype"
Override ignored for property "querytype"
Property "spotport" has not been set
Override ignored for property "spotselector.preferred.port"
[mkdir] Skipping C:\Program Files\Sun\SunSPOT\sdk\temp because it already exists.
Property "spotclient.verbose" has not been set
[java] Executing 'C:\Program Files\Java\jdk1.5.0_16\jre\bin\java.exe' with arguments:
[java] '-Djava.library.path=C:/Program Files/Sun/SunSPOT/sdk/lib'
[java] '-Dspotselector.inhibit.full.basestation.check=false'
[java] '-Dverbose=${spotclient.verbose}'
[java] '-classpath'
[java] 'C:\Program Files\Sun\SunSPOT\sdk\lib\spotselector.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\multihoplib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\transducerlib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_host.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_common.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\squawk_classes.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\RXTXcomm.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotclient.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\desktop_signing.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_spotclient.jar;C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop'
[java] 'com.sun.spot.spotselector.CommandLineSpotSelector'
[java] 'COM7 (00144F0100004BFD)'
[java] '2'
[java] 'COM7'
[java] 'C:\Program Files\Sun\SunSPOT\sdk\temp\spotselector-999496015'
[java]
[java] The ' characters around the executable and arguments are
[java] not part of the command.
[java] Please wait while connected Sun SPOTs are examined...
Property "basestation.not.required" has not been set

-collect-spotselector-result:
[loadfile] loading C:\Program Files\Sun\SunSPOT\sdk\temp\spotselector-999496015 into property port
[loadfile] loaded 4 characters
[echo]
[echo] Using Sun SPOT basestation on port COM7

-clean-up-spotselector-output-file:
[delete] Deleting: C:\Program Files\Sun\SunSPOT\sdk\temp\spotselector-999496015

-spotselector-fail:
Skipped because property 'spotselector.spotselector.failed' not set.

-decide-whether-to-start-basestation-manager:

-start-new-basestation-manager:
Skipped because property 'spotselector.should.start.shared.basestation' not set.

-do-find-spots:
Override ignored for property "port"

-pre-host-compile:

-do-host-compile:
[mkdir] Skipping C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build because it already exists.
[javac] org\sunspotworld\demo\AccelerometerListener.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\AccelerometerListener.class is up to date.
[javac] org\sunspotworld\demo\GraphView.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\GraphView.class is up to date.
[javac] org\sunspotworld\demo\PacketTypes.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\PacketTypes.class is up to date.
[javac] C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\src\org\sunspotworld\demo\TelemetryFrame.form skipped - don't know how to handle it
[javac] org\sunspotworld\demo\TelemetryFrame.java omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\TelemetryFrame.class is up to date.
[javac] C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\src\org\sunspotworld\demo\package.html skipped - don't know how to handle it
[javac] C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\src\org\sunspotworld\demo\racecar.gif skipped - don't know how to handle it

-post-host-compile:
[copy] org\sunspotworld\demo\racecar.gif omitted as C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build\org\sunspotworld\demo\racecar.gif is up to date.
[copy] No sources found.

host-compile:

-pre-host-run:

-do-host-run:
[java] Executing 'C:\Program Files\Java\jdk1.5.0_16\jre\bin\java.exe' with arguments:
[java] '-Djava.library.path=C:/Program Files/Sun/SunSPOT/sdk/lib;'
[java] '-DSERIAL_PORT=COM7'
[java] '-Dremote.channel=26'
[java] '-Dremote.pan.id=3'
[java] '-Dspot.mesh.route.logging=false'
[java] '-Dspot.log.connections=true'
[java] '-Dspot.basestation.sharing=false'
[java] '-Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension,'
[java] '-classpath'
[java] 'C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build;C:\Program Files\Sun\SunSPOT\sdk\lib\multihoplib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\transducerlib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_host.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_common.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\squawk_classes.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\RXTXcomm.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotclient.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\desktop_signing.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_spotclient.jar;C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop'
[java] 'org.sunspotworld.demo.TelemetryFrame'
[java]
[java] The ' characters around the executable and arguments are
[java] not part of the command.
[java] [radiogram] Adding: Server on port 42
[java] [radiogram]Removing: Server on port 42
[java] Accelerometer Reader Thread Started ...
[java] [radiogram] Adding: Broadcast on port 43
[java] [radiogram]Removing: Broadcast on port 43
[java] [radiogram] Adding: Server on port 42
[java] Received request from: 0014.4F01.0000.4D86
[java] [radiogram]Removing: Server on port 42
[java] [radiogram] Adding: Output to 0014.4F01.0000.4D86 on port 43
[java] [radiogram] Adding: Input from 0014.4F01.0000.4D86 on port 43
[java] Accelerometer scale is set to 2G
[java] Accelerometer zero offsets:
[java] 2G: 465.0, 465.0, 465.0
[java] 6G: 465.0, 465.0, 465.0
[java] Accelerometer gains:
[java] 2G: 186.0, 186.0, 186.0
[java] 6G: 62.0, 62.0, 62.0
[java] Accelerometer rest offsets:
[java] 2G: 465.0, 465.0, 651.0
[java] 6G: 465.0, 465.0, 527.0
[java] Accelerometer scale is set to 2G
[java] Accelerometer zero offsets:
[java] 2G: 465.0, 465.0, 465.0
[java] 6G: 465.0, 465.0, 465.0
[java] Accelerometer gains:
[java] 2G: 186.0, 186.0, 186.0
[java] 6G: 62.0, 62.0, 62.0
[java] Accelerometer rest offsets:
[java] 2G: 465.0, 465.0, 651.0
[java] 6G: 465.0, 465.0, 527.0
[java] Accelerometer rest offsets:
[java] 2G: 475.0, 471.0, 638.0
[java] 6G: 468.0, 469.0, 526.0

-post-host-run:

host-run:

BUILD SUCCESSFUL
Total time: 34 seconds

2. Beware of the red text area, it contains key information we need to execute Sun SPOT host side application without ANT. What we need to do is re-construct the parameters to a command. Finally, We get:

java -Djava.library.path="C:/Program Files/Sun/SunSPOT/sdk/lib"; -DSERIAL_PORT=COM7 -Dremote.channel=26 -Dremote.pan.id=3 -Dspot.mesh.route.logging=false -Dspot.log.connections=true -Dspot.basestation.sharing=false -Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension, -classpath "C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop\build;C:\Program Files\Sun\SunSPOT\sdk\lib\multihoplib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\transducerlib_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_rt.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_host.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotlib_common.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\squawk_classes.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\RXTXcomm.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotclient.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\desktop_signing.jar;C:\Program Files\Sun\SunSPOT\sdk\lib\spotworldext_spotclient.jar;C:\Program Files\Sun\SunSPOT\Demos\TelemetryDemo\Telemetry-onDesktop" org.sunspotworld.demo.TelemetryFrame

3. Or, maybe you want to invoke the application from another Java application. Please use the command below:

"java -Djava.library.path=\"C:/Program Files/Sun/SunSPOT/sdk/lib\"; -DSERIAL_PORT=COM7 -Dremote.channel=26 -Dremote.pan.id=3 -Dspot.mesh.route.logging=false -Dspot.log.connections=true -Dspot.basestation.sharing=false -Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension, -classpath \"C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/build;C:/Program Files/Sun/SunSPOT/sdk/lib/multihoplib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/transducerlib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_host.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_common.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/squawk_classes.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/RXTXcomm.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotclient.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/desktop_signing.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_spotclient.jar;C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/\" org.sunspotworld.demo.TelemetryFrame"

4. This is the source code of Java invoker which invokes the Sun SPOT host side application without ant:

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package simpleinvoker;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
*
* @author pdeng
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
try {
// TODO code application logic here
String line;
Process p = Runtime.getRuntime().exec("java -Djava.library.path=\"C:/Program Files/Sun/SunSPOT/sdk/lib\"; -DSERIAL_PORT=COM7 -Dremote.channel=26 -Dremote.pan.id=3 -Dspot.mesh.route.logging=false -Dspot.log.connections=true -Dspot.basestation.sharing=false -Dspotclient.addin.classes=com.sun.spot.client.command.spotworld.SpotWorldSpotClientExtension, -classpath \"C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/build;C:/Program Files/Sun/SunSPOT/sdk/lib/multihoplib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/transducerlib_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_rt.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_host.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotlib_common.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/squawk_classes.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/RXTXcomm.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotclient.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/desktop_signing.jar;C:/Program Files/Sun/SunSPOT/sdk/lib/spotworldext_spotclient.jar;C:/Program Files/Sun/SunSPOT/Demos/TelemetryDemo/Telemetry-onDesktop/\" org.sunspotworld.demo.TelemetryFrame");
BufferedReader input =
new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

2008年7月14日星期一

Simplest Java SE Web Service Tutorial

CircleFunctions.java

package geometricalws;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

@WebService(name = "Circle", serviceName = "CircleService", portName = "CirclePort")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class CircleFunctions {

@WebMethod(operationName = "area")
public double getArea(@WebParam(name = "r") double r) {
return Math.PI * (r * r);
}

@WebMethod(operationName = "circumference")
public double getCircumference(@WebParam(name = "r") double r) {
return 2 * Math.PI * r;
}
}

Main.java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package geometricalws;

import javax.xml.ws.Endpoint;

/**
*
* @author Administrator
*/

public class Main {

/**
* @param args the command line arguments
*/

public static void main(String[] args) {
String wsAddress = "http://localhost:8765/GeometricalWS/CircleFunctions";
Endpoint.publish(wsAddress, new CircleFunctions());
System.out.println("Web service was published successfully.\n" +
"WSDL URL: " + wsAddress + "?WSDL");
// Keep the local web server running until the process is killed
while (Thread.currentThread().isAlive()) {
try {
Thread.sleep(10000);
} catch (InterruptedException ex) {
}
}
}
}





Read this document on Scribd: nb02-part6-jsews

2008年7月12日星期六

Change local in NetBeans IDE

My operating platform is Chinese version, while I prefer to user English version IDE. It's strange that the menu and label are still Chinese words even if I downloaded and installed a English version NetBeans. Java's i18n is great, so NetBeans can adjust its local according to Operating Platform by default.
To change the NetBeans local to English version, modify the file $NETBENA_HOME/etc/netbeans.conf
add "--local en" in "netbeans_default_options"
For example, the original:
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true "
Modified:
netbeans_default_options="-J-Xms32m -J-Xmx128m -J-XX:PermSize=32m -J-XX:MaxPermSize=160m -J-Xverify:none -J-Dapple.laf.useScreenMenuBar=true --locale en"

http://lilyblack.spaces.live.com/Blog/cns!90FA6316A38FD1CD!236.entry

2008年6月12日星期四

Markov and You

http://www.codinghorror.com/blog/archives/001132.html

In Finally, a Definition of Programming I Can Actually Understand I marvelled at particularly strange and wonderful comment left on this blog. Some commenters wondered if that comment was generated through Markov chains. I considered that, but I had a hard time imagining a text corpus input that could possibly produce output so profoundly weird.

So what are these Markov chains we're talking about?

One example of Markov chains in action is Garkov, where the long running Garfield cartoon strip meets Markov chains. I present below, for your mild amusement, two representative strips I found on the Garkov hall of fame:

garkov-sample-1.png

garkov-sample-2.png

Garfield's an easy target, though:

  • Garfield Minus Garfield. What it says on the tin. Surprisingly cathartic.
  • Lasagna Cat. Almost indescribably strange live action recreations of Garfield strips. If you only click one link in this post, make it this one. Sanity optional.
  • Garfield Variations. Hand-drawn versions of Garfield in underground "comix" style, usually on paper napkins.
  • Barfield. Garfield strips subtly modified to include amusing bodily functions.
  • Permanent Monday. Literary commentary on selected strips.
  • Arbuckle. Strips faithfully redrawn by random internet "artists", with one dramatic twist: Jon can't actually hear Garfield, because he is, after all, a cat.
  • Garfield Randomizer. Sadly defunct -- combined random panels to form "new" Garfield strips.

So let's proceed to the "kov" part of Garkov. The best description of Markov chains I've ever read is in chapter 15 of Programming Pearls:

A generator can make more interesting text by making each letter a random function of its predecessor. We could, therefore, read a sample text and count how many times every letter follows an A, how many times they follow a B, and so on for each letter of the alphabet. When we write the random text, we produce the next letter as a random function of the current letter. The Order-1 text was made by exactly this scheme:
t I amy, vin. id wht omanly heay atuss n macon aresethe hired boutwhe t, tl, ad torurest t plur I wit hengamind tarer-plarody thishand.

We can extend this idea to longer sequences of letters. The order-2 text was made by generating each letter as a function of the two letters preceding it (a letter pair is often called a digram). The digram TH, for instance, is often followed in English by the vowels A, E, I, O, U and Y, less frequently by R and W, and rarely by other letters.

Ther I the heingoind of-pleat, blur it dwere wing waske hat trooss. Yout lar on wassing, an sit." "Yould," "I that vide was nots ther.

The order-3 text is built by choosing the next letter as a function of the three previous letters (a trigram).

I has them the saw the secorrow. And wintails on my my ent, thinks, fore voyager lanated the been elsed helder was of him a very free bottlemarkable,

By the time we get to the order-4 text, most words are English, and you might not be surprised to learn that it was generated from a Sherlock Holmes story ( "The Adventure of Abbey Grange'').

His heard." "Exactly he very glad trouble, and by Hopkins! That it on of the who difficentralia. He rushed likely?" "Blood night that.

So the text in Garkov strips is generated in exactly this way, but using words instead of letters. The input corpus is, as you'd expect, the text of many old Garfield strips.

What's amazing to me about Markov chains is how unbelievably simple they are. A Markov chain has no memory of previous states: the next state (word, in our case) is chosen based on a random dice roll and a lookup into a table of the states that tend to historically follow the current state in the input corpus. Given an adequate input corpus, they work almost uncannily well, a testament to the broad power of rudimentary statistical inference. Garfield's been around since 1978, and still going str.. well, going, so there's no shortage of material to work with.

Now let's try it ourselves. I fed the text of the last twelve Paul Graham essays to this online Markov generator, using two word groupings -- what Bentley refers to as "Order-2". Here's what I got back:

You can feel the need to take advantage of increased cheapness, however. You're not all playing a zero-sum game. There's not some fixed number of startups; we fund startups we fund to work on matters of passing importance. But I'm uncomfortably aware that this is part of any illusions about the problem of overeating by stopping eating. I couldn't simply avoid the Internet had become, because the company is the new trend of worrying obsessively about what it meant for someone, usually an outsider, who deliberately stirred up fights in a startup than just start it. You know how the A List is selected. And even that is more work.

But Markov chains aren't just useful for automatically generating Paul Graham essay parodies. They're also quite practical. You might even say Markov chains are a large part of what powers today's internet. Most remarkably, to me at least, Markov chains underly Google's trillion dollar PageRank formula:

The [PageRank] formula uses a model of a random surfer who gets bored after several clicks and switches to a random page. The PageRank value of a page reflects the chance that the random surfer will land on that page by clicking on a link. [PageRank] can be understood as a Markov chain in which the states are pages, and the transitions are all equally probable and are the links between pages.

As a result of Markov theory, it can be shown that the PageRank of a page is the probability of being at that page after lots of clicks. This happens to equal t-1 where t is the expectation of the number of clicks (or random jumps) required to get from the page back to itself.

Incidentally, if you haven't read the original 1998 PageRank paper, titled The PageRank Citation Ranking: Bringing Order to the Web (pdf), you really should. It's remarkable how, ten years on, so many of the predictions in this paper have come to pass. It's filled with interesting stuff; the list of the top 15 PageRank sites circa 1996 in Table 1 is an eye-opening reminder of how far we've come. Plus, there are references to pornographic sites, too!

Markovian models -- specifically, hidden Markov Models -- are also related to our old friend, Bayesian spam filtering. They're even better! The most notable example is the CRM114 Discriminator, as outlined in this excellent presentation (pdf).

How to Turn a Bayesian into a Markovian

If you play with the Markov text synthesizer, you'll quickly find that Markov methods are only as good as their input corpus. Input a bunch of the same words, or random gibberish, and that's what you'll get back.

But it's sure tough to imagine a more ideal input corpus for Markovian techniques than the unimaginable vastness of web and email, isn't it?

[advertisement] Read the largest case study ever published about lightweight peer code review in Best Kept Secrets of Peer Code Review. Free book, free shipping.

3D Accelerometer Based Gesture Control Human Computer Interface

ABSTRACT: We developed a gesture based human computer interaction interface. Wireless sensor node is used to capture human body acceleration data. To segment received acceleration data stream, we developed an algorithm based on sliding window and standard deviation. To recognize gesture, Hidden Markov Model (HMM) which is a machine learning algorithm is used. Series prototype applications are built to demonstrate possible gesture based applications in future. We conducted several experiments as well. Finally, we got highest 96% accuracy and lowest 17% accuracy.

KEYWORDS: body sensor network, wireless sensor network, data stream processing, hidden markov model, machine learning, gesture recognition, human-computer interface

Source code will be available later