0% found this document useful (0 votes)
128 views

Developing Java Applications: For Intermec Computers

Uploaded by

Ardityo Navy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views

Developing Java Applications: For Intermec Computers

Uploaded by

Ardityo Navy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Developing Java

Applications
for Intermec Computers
Intermec Technologies Corporation
Worldwide Headquarters
6001 36th Ave.W.
Everett, WA 98203
U.S.A.
www.intermec.com
The information contained herein is provided solely for the purpose of allowing customers to operate and service
Intermec-manufactured equipment and is not to be released, reproduced, or used for any other purpose without
written permission of Intermec Technologies Corporation.
Information and specifications contained in this document are subject to change without prior notice and do not
represent a commitment on the part of Intermec Technologies Corporation.
© 2010 by Intermec Technologies Corporation. All rights reserved.
The word Intermec, the Intermec logo, Norand, ArciTech, Beverage Routebook, CrossBar, dcBrowser, Duratherm,
EasyADC, EasyCoder, EasySet, Fingerprint, INCA (under license), i-gistics, Intellitag, Intellitag Gen2, JANUS,
LabelShop, MobileLAN, Picolink, Ready-to-Work, RoutePower, Sabre, ScanPlus, ShopScan, Smart Mobile
Computing, SmartSystems, TE 2000, Trakker Antares, and Vista Powered are either trademarks or registered
trademarks of Intermec Technologies Corporation.
There are U.S. and foreign patents as well as U.S. and foreign patents pending.
Microsoft, Windows, and the Windows logo are registered trademarks of Microsoft Corporation in the United
States and/or other countries.

ii Developing Java Applications for Intermec Computers


Contents

Contents
Before You Begin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Global Services and Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Warranty Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Web Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Telephone Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
Who Should Read This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi
Related Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi

Developing Java Applications for Intermec Computers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7

About the Java Runtime Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7


Java Platform Micro Edition (Java ME) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
Java ME Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
Connected Device Configuration. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
Java ME External Links. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
JVMs Based on Java ME CDC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
About the IBM WebSphere Everyplace Micro Environment. . . . . . . . . . . . . . . . . . . .9
About NSIcom CrE-ME . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9

About the Integrated Development Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10


Using the Eclipse IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Creating A HelloWorld Java Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Setting Project Compiling Source Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Creating A HelloWorld Java Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
Coding the HelloWorld Java Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
Exporting to HelloWorld.jar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
About the JAR Warning Export Message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Deploying the HelloWorld Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Using the NetBeans IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Installing the Java ME Plug-in . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Installing a CDC Emulator Platform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .19
Creating a HelloWorld Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22
Creating a HelloWorld Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
Coding the HelloWorld Java Class. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
Building the HelloWorld Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Running HelloWorld in Emulator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .25
Deploying the HelloWorld Application to CrE-ME . . . . . . . . . . . . . . . . . . . . . . . . . .27
Deploying the HelloWorld Application to WEME . . . . . . . . . . . . . . . . . . . . . . . . . . .28

Deploying Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29


Creating the Application Shortcut File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Copying Files to the Mobile Computer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Running the Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30

Remote Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30


Creating a Shortcut for Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
Deploying and Starting a Debug Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
Remote Debugging in Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Setting and Starting the IDE Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32

Developing Java Applications for Intermec Computers iii


Contents

Remote Debugging in NetBeans. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34


Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
Setting and Starting IDE Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .35

Accessing Databases Using JDBC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37


JDBC Sample Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
Building the Sample. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
Running the Sample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
Adapting the Sample for Other DBMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39

Developing a Web Services Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40


Developing a Web Services Client in Eclipse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
Creating a StockQuoteWTK Java Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
Setting the Project Compiling Source Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Generating Web Services Stubs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Importing Generated Stub Classes to Eclipse. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .47
Creating a Java Class to Call the Web Services API . . . . . . . . . . . . . . . . . . . . . . . . . . .49
Exporting Classes to StockQuoteWTK.jar. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
Deploying the Web Services Client to the Mobile Computer . . . . . . . . . . . . . . . . . .53
Developing a Web Services Client in NetBeans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
Creating the StockQuoteWTK Java Project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
Adding Web Services JAR Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .57
Generating Web Services Stubs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
Creating a Java Class to Call the Web Services API . . . . . . . . . . . . . . . . . . . . . . . . . . .59
Building the StockQuoteWTK Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60
Deploying StockQuoteWTK onto Mobile Computer. . . . . . . . . . . . . . . . . . . . . . . . .60

Glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62

iv Developing Java Applications for Intermec Computers


Before You Begin

Before You Begin


This section provides you with safety information, technical support information,
and sources for additional product information.

Global Services and Support


Warranty Information
To understand the warranty for your Intermec product, visit the Intermec web site at
www.intermec.com and click Support > Returns and Repairs > Warranty.
Disclaimer of warranties: The sample code included in this document is presented
for reference only. The code does not necessarily represent complete, tested
programs. The code is provided “as is with all faults.” All warranties are expressly
disclaimed, including the implied warranties of merchantability and fitness for a
particular purpose.

Web Support
Visit the Intermec web site at www.intermec.com to download our current manuals
(in PDF).
Visit the Intermec technical knowledge base (Knowledge Central) at
intermec.custhelp.com to review technical information or to request technical
support for your Intermec product.

Telephone Support
In the U.S.A. and Canada, call 1-800-755-5505.
Outside the U.S.A. and Canada, contact your local Intermec representative. To
search for your local representative, from the Intermec web site, click About Us >
Contact Us.

Service Location Support


For the most current listing of service locations, go to www.intermec.com and click
Support >Returns and Repairs > Repair Locations.
For technical support in South Korea, use the after service locations listed below:
AWOO Systems
102-1304 SK Ventium
522 Dangjung-dong
Gunpo-si, Gyeonggi-do Korea, South 435-776
Contact: Mr. Sinbum Kang
Telephone: +82-31-436-1191
E-mail: [email protected]
IN Information System PTD LTD
6th Floor
Daegu Venture Center Bldg 95
Shinchun 3 Dong
Donggu, Daegu City, Korea
E-mail: [email protected] or [email protected]

Developing Java Applications for Intermec Computers v


Before You Begin

Who Should Read This Manual


This document is intended for Java developers who create applications for Intermec
mobile computers and peripherals. You should be familiar with:
• general programming techniques for Java applications.
• your Intermec computers and peripherals.
• Java IDEs such as Eclipse or NetBeans.
• concepts for software design.

Related Documents
The Intermec web site at www.intermec.com contains our documents (as PDF files)
that you can download for free.
To download documents
1 Visit the Intermec web site at www.intermec.com.
2 Click the Products tab.
3 Using the Products menu, navigate to your product page. For example, to find
the CN3 computer product page, click Computers > Handheld Computers >
CN3.
4 Click the Manuals tab.
If your product does not have its own product page, click Support > Manuals. Use
the Product Category field, the Product Family field, and the Product field to
help you locate the documentation for your product.

vi Developing Java Applications for Intermec Computers


Developing Java Applications for Intermec Computers
This document is intended for developers who create Java applications for Intermec
Windows Mobile and CE-based mobile computers. This document assumes the
developers are already familiar with general Java programming concepts. Due to the
characteristics of the mobile computers, development requirements may be
different from desktop application development. This document provides
requirements and development tool information, and guides you through the
development process with examples. It covers the following topics:
• About the Java Runtime Environment
Discusses the JRE requirements and provides recommendations for Intermec
mobile computers.
• About the Integrated Development Environment
Covers mobile development guidelines, and provides step-by-step instructions
for creating a simple mobile application in Eclipse and NetBeans IDEs.
• Deploying Applications
Explains how to deploy a Java application to the mobile computer.
• Remote Debugging
Describes how to setup the IDE and the mobile computer for remote debugging.
• Accessing Databases Using JDBC
Discusses the JDBC API available for mobile computers and provides an example
to connect to a database. The JDBC API enables Java applications to access SQL-
based databases or tabular data sources.
• Developing a Web Services Client
Discusses the web services support for mobile computers and provides a tutorial
for developing a web services client. Web services are APIs that can be accessed
over a network regardless of systems and languages.

About the Java Runtime Environment


The Java runtime environment contains the Java virtual machine (JVM) and class
libraries necessary to run Java applications. In this document, the term JVM is used
interchangeably with JRE.

Java Platform Micro Edition (Java ME)


Due to the limited resources on mobile computers, Intermec recommends a Java
runtime environment that is based on Java Platform, Micro Edition (Java ME). The
Java ME platform consists of these elements:
• Configuration – a core set of APIs and virtual machine capabilities for a broad
range of devices.
• Profile – a set of APIs that support a narrower range of devices. A profile is built
on a specific configuration.

Developing Java Applications for Intermec Computers 7


• Optional Packages – a set of technology-specific APIs that extends the
functionality of a Java application environment. Optional packages must be
used in conjunction with a configuration or a profile.

Java ME Configurations
Java ME supports two configurations:
• Connected Limited Device Configuration (CLDC) is for resource-constrained
devices like mobile phones and entry-level personal digital assistants (PDAs). It
has a very limited set of APIs, and is designed to run on devices with limited
memory, processing power and graphics capabilities.
• Connected Device Configuration (CDC) is for network-connected devices that
have more memory and processing power, such as high-end PDAs.
Intermec Windows Mobile and CE-based computers are certainly in the high-end
PDAs category and meet the requirements of CDC; therefore, Intermec recommends
CDC for Intermec computers. The focus of this document is on the CDC.
CDC is a superset of CLDC; therefore, CLDC is upward compatible with CDC.
However, the CLDC Mobile Information Device Profile (MIDP) is not compatible
with CDC. If your existing application is based on MIDP and you do not wish to
revamp your application for CDC, you may install a JVM that supports MIDP such
as IBM WebSphere Everyplace Micro Environment with MIDP 2.0.

Connected Device Configuration


CDC has two versions CDC 1.0 (JSR 36) and 1.1 (JSR 218). CDC 1.0 contains a
subset of APIs from Java Platform Standard Edition (Java SE) 1.3. CDC 1.1 provides
updates and adds selected APIs based on Java SE 1.4. One of the benefits of
developing with CDC is that it is upward compatible with Java SE.
CDC supports three profiles: Foundation Profile, Personal Basis Profile and
Personal Profile. Intermec supports Personal Profile which has full AWT 1.1 support
and includes all the APIs in the Foundation Profile and Personal Basis Profile. The
AWT implementation in Personal Profile is based on JDK 1.1 and has some 2D
packages from Java SE.
AWT provides a basic set of graphical user interface (GUI) components that were
implemented using native-platform versions of the components. For a richer look
and feel, consider other widget toolkits such as the Standard Widget Toolkit
(SWT) by Eclipse.

Java ME External Links


For more information on Java ME, see these web links:
• Java ME: the Most Ubiquitous Application Platform for Mobile Devices
• Java ME Technology - CDC
• Java ME Personal Profile
• CDC: Java Platform Technology for Connected Devices White Paper

8 Developing Java Applications for Intermec Computers


JVMs Based on Java ME CDC
Sun Microsystems, now a subsidiary of Oracle Corporation, does not provide a Java
ME CDC implementation for the Windows Mobile platform. Intermec recommends
the IBM WebSphere Everyplace Micro Environment (WEME) that implements
CDC/Personal Profile 1.1. All the Java class libraries in the Intermec Developer
Library (IDL) Resource Kits were tested against WEME. For more information, see
the next section, “About the IBM WebSphere Everyplace Micro Environment.”
Another popular JVM for Windows Mobile/CE computers is CrE-ME by NSIcom.
CrE-ME version 4 implements CDC/Personal Profile 1.0. Some applications such as
SAP Mobile Infrastructure clients may require CrE-ME. You can choose this JVM if
it better fits your needs, but you may not get the same level of support from
Intermec. For CrE-ME related issues, you need to contact NSIcom for support.
The following sections have more details on WEME and CrE-ME.

About the IBM WebSphere Everyplace Micro


Environment
The IBM WebSphere Everyplace Micro Environment (WEME) contains the Java
virtual machine (J9) and class libraries necessary to run Java applications on mobile
computers. It is often referred to as J9.
Intermec currently resells WEME 6.2 for Windows Mobile 6.1 (P/N 454-035-001),
which targets Windows Mobile 6.1 computers such as the CK3, CN3, CN4, and
CN50. WEME 6.2 contains CDC/Personal Profile 1.1 with optional packages: JCE,
JSSE, JDBC, and RMI.
You can download the API specifications for the Personal Profile and the supported
optional packages from these links:
• JSR-000216 Personal Profile 1.1 Specification
• JSR-000219 Foundation Profile 1.1 – Includes API specifications for JCE
and JSSE.
• JSR-000169 JDBC Optional Package Specification
• JSR-000066 RMI Optional Package Specification

About NSIcom CrE-ME


NSIcom originally offered CrEme 3, which implemented Personal Java 3.1. Personal
Java is based on JDK 1.1.8 and it has been discontinued. If you use this version of
CrEme, you need a JDK 1.1 compiler to build your application.
NSIcom later introduced a new version of CrEme based on Java ME and rebranded it
to CrE-ME. CrE-ME 4 implements CDC/Personal Profile 1.0. To use the Java class
libraries in the Intermec Developer Library (IDL) Resource Kits with CrEme, you
must use CrE-ME version 4.
CrE-ME 4 supports different Windows Mobile/CE versions. You can download trial
versions from the NSIcom web site. CrE-ME 4 has advantages and disadvantages:
• It supports Swing and Java plug-ins for Pocket Internet Explorer, which WEME
does not support.

Developing Java Applications for Intermec Computers 9


• Its default and preferred graphics library is based on the Truffle implementation
of AWT. The look and feel are different from standard AWT.
• The major drawback of CrE-ME is its Java Native Interface (JNI)
implementation. The JNI invocation would block the VM operation. If a JNI
method is called from a thread in a Java application, all threads in the
application are blocked until the JNI call returns.
There are two ways to prevent a blocking JNI call from blocking the entire
application. The easiest way is to specify the “-noblock” VM option in the command
line you use to start your application. The preferred way recommended by NSIcom
is to call the creme.Noblock.on method before the JNI call, and creme.Noblock.off
method after the JNI call.
Because of CrE-ME’s JNI implementation, some IDL Java classes (such as
BarcodeReader and Imager) will not work properly. It is not desirable to add CrE-
ME specific library calls in the IDL libraries. Therefore, Intermec recommends that
you specify the “-noblock” VM option in the application shortcut if you use the
aforementioned IDL Java classes. For more on application shortcuts, see “Creating
the Application Shortcut File” on page 29.

About the Integrated Development Environment


Most Java Integrated Development Environments (IDEs) on the market today target
Java Platform Standard Edition (SE) or Enterprise Edition (EE) development.
However, not all Java IDEs have adequate support for mobile development.
Although you may use your preferred Java IDE for developing mobile applications,
there are two rules you need to follow to ensure that your application can be
deployed successfully to Intermec mobile computers.
• Rule #1: Know the Java standard supported by the JVM on your mobile
computer.
The Java IDE usually selects the highest JDK version installed on your desktop
computer as the default compiler. WEME and CrE-ME implement Java ME CDC
Personal Profile and some optional packages. Unless the IDE provides a JVM
emulator that matches the JVM on your mobile computer, you need to be careful
to call only the Java APIs supported by the target JVM. Otherwise, your
application may get a runtime error even if it compiles successfully in the IDE.
• Rule #2: Adjust the project compiling source level to match the JVM on your
mobile computer.
The byte code generated by the JDK may not be compatible with the JVM on your
mobile computer. The IDE project setting should allow you to adjust the
compiling source level. If the default compiler version of your IDE is JDK 1.5 (or
JDK 5) or higher, you should set the compiling source level to 1.4 for both
WEME and CrE-ME. If you use javac to compile your source code, you should
add “-source 1.4” to the compiler options.
The next sections walk you through building a simple HelloWorld application using
two popular, open-source IDEs, Eclipse and NetBeans.

10 Developing Java Applications for Intermec Computers


Using the Eclipse IDE
The Eclipse IDE is one of the most popular Java IDEs. There are numerous plug-ins
available to extend the capabilities of the IDE. Although Eclipse has a plug-in called
Mobile Tools for Java (MTJ), the current version (1.0.1) only supports Java ME
CLDC MIDP. Since it does not support CDC Personal Profile, you can simply create
a regular Java project in Eclipse and follow the rules mentioned before. You may
download one of the Eclipse IDEs for Java from Eclipse Downloads.
The following tutorial walks you through the process of creating a simple
HelloWorld application in Eclipse. All screenshots were captured using Eclipse IDE
for Java EE Developers version 3.5 (Galileo), running on Windows XP.

Creating A HelloWorld Java Project


This section explains how to create a simple “Hello World” project in the Eclipse
IDE.
To create the project
1 From the menu bar, select File > New > Java Project. The New Java Project
dialog box appears.
2 In the Project name field, enter HelloWorld.

Developing Java Applications for Intermec Computers 11


3 Click Finish.
Note: The Create new project in workspace button specifies that the project
folder will be created under the default Eclipse workspace directory.

Setting Project Compiling Source Level


1 In Package Explorer, right-click the HelloWorld project and choose Properties
in the popup menu. The Properties for HelloWorld dialog box appears.
2 In the navigation pane, click the Java Compiler node.
3 Uncheck the Use compliance from execution environment ‘JavaSE-1.6’ on
the Java Build Path checkbox.
4 Uncheck the Use default compliance settings check box.
5 Set the Generated .class files compatibility and Source compatibility values
to 1.4. This ensures the generated byte code will be compatible with WEME and
CrE-ME 4.

6 Click OK.

Creating A HelloWorld Java Class


1 In Package Explorer, right-click the HelloWorld project and choose New > Class
in the popup menu. The New Java Class dialog box appears.
2 In the Package field, enter sample for the package name.
3 In the Name field, enter HelloWorld for the class name.

12 Developing Java Applications for Intermec Computers


4 In the Superclass field, enter or browse to java.awt.Frame.

5 Click Finish.

Coding the HelloWorld Java Class


Copy the following code to the HelloWorld Java class and click .
package sample;

import java.awt.*;
import java.awt.event.*;

public class HelloWorld extends Frame {


private Label m_LabelHello = new Label("Hello World!");
private Button m_ButtonClose = new Button("Close");

public HelloWorld(String aTitle)


{
super(aTitle);
initComponents();
}

private void initComponents()


{
add(m_LabelHello, BorderLayout.CENTER);
add(m_ButtonClose, BorderLayout.SOUTH);

m_ButtonClose.addActionListener(new ActionListener()
{
// Invoked when the Close button is clicked.
public void actionPerformed(ActionEvent e)

Developing Java Applications for Intermec Computers 13


{
dispose();
System.exit(0);
}
});
}

public static void main(String[] args)


{
HelloWorld hwApp = new HelloWorld("Hello World");
hwApp.setSize(200, 200);
hwApp.setVisible(true);
}
}

This simple application displays the “Hello World!” string in the north of the frame
and a Close button at the south of the frame. Click Close to exit the application.

Exporting to HelloWorld.jar
1 In the Package Explorer, right-click the src folder under HelloWorld and choose
Export from the popup menu.
2 In the Export dialog box, choose JAR file under the Java node and click Next.

3 In the JAR File Specification screen, click Browse. The Save As dialog box
appears.

14 Developing Java Applications for Intermec Computers


4 Browse to the HelloWorld project folder, enter HelloWorld.jar in the File
name field, and then click Save.

In the JAR File Specification screen, the JAR file list now includes “HelloWorld/
HelloWorld.jar”. This specifies the output JAR file, HelloWorld.jar, will be
created in the HelloWorld project folder.

To create a runnable JAR, the JAR manifest needs to contain the Main-Class
attribute with the proper main class name. Continue with the next step to create
a runnable JAR, or continue with Step 8 to finish the export.

Developing Java Applications for Intermec Computers 15


5 Click Next twice. The JAR Manifest Specification screen appears.
6 Click Browse. The Select Main Class dialog box appears.

7 Select HelloWorld from the list and click OK.

In the JAR Manifest Specification screen, sample.HelloWorld appears in the


Main class field.

8 Click Finish if there are no more changes you wish to make.

16 Developing Java Applications for Intermec Computers


About the JAR Warning Export Message
If you see this JAR Export warning message, click OK and ignore it:

This compile warning appears because the HelloWorld Java class does not declare
the “static final long serialVersionUID” field. To avoid the compile warning, define
serialVersionUID properly using the UID obtained from the serialver utility
(included in JDK).

Deploying the HelloWorld Application


To deploy the HelloWorld application, copy HelloWorld.jar to the mobile computer.
If you followed the procedure in ‘‘Exporting to HelloWorld.jar’’ to specify the
main class in the JAR manifest, HelloWorld.jar is a runnable JAR file.
If you have the CrEme JVM installed on your mobile computer, browse to
HelloWorld.jar and tap the filename to run it. To add additional VM options for
your application, or to run a Java application with WEME, you need to create an
application shortcut. For more information, see “Creating the Application
Shortcut File” on page 29.

Developing Java Applications for Intermec Computers 17


Using the NetBeans IDE
NetBeans IDE has been greatly improved over the years and become a very
competitive open-source IDE. Like Eclipse, NetBeans supports plug-ins to extend
the IDE’s capabilities. One of its great features is its Java ME CDC development
support. This section describes how to create a CDC Personal Profile 1.0 application
in NetBeans.

All screenshots in this section were captured using NetBeans 6.8 running on
Windows XP. You may download NetBeans from the NetBeans Download site.
There are different bundles of NetBeans you can choose to download. Intermec
recommends that you choose a bundle which includes Java ME.

18 Developing Java Applications for Intermec Computers


Installing the Java ME Plug-in
If you did not choose a NetBeans bundle that includes Java ME, you need to install
the Java ME Plug-in. You may check the current plug-ins installed in NetBeans.
From the menu bar, select Tools > Plug-ins. In the Plug-ins dialog box, click the
Installed tab to show the list of installed plug-ins. Make sure Java ME is in the list. If
you do not see Java ME in the list, install it from the Available Plug-ins tab.

Installing a CDC Emulator Platform


An emulator platform provides the SDK and emulation environment for you to
build and test for the target platform. The NetBeans web site provides the CDC
Emulator Platform Setup Guide for the supported CDC emulators. Currently the
best matched emulator is the CrEme emulator. This emulator emulates the CrE-ME
4 VM. If you are already using CrE-ME 4 on your mobile computer, this is a perfect
match. Even if your target JVM is WEME, the generated .class files will be
compatible since CrE-ME 4 is compliant with CDC/Personal Profile 1.0. However,
you should avoid the Swing classes which are only supported in CrE-ME.
Note: If your target JVM is WEME and you need the APIs in Personal Profile 1.1 that
are not supported by the CrEme emulator, create a regular Java application project
and observe the rules described in “About the Integrated Development
Environment” on page 10.

To install the CrEme emulator


1 Download CrEmeDevSup410.exe from NSIcom.
2 Run the file and follow the prompts to install the Developer Kit.
3 In the NetBeans IDE menu bar, select Tools > Java Platforms.
4 In the Java Platform Manager dialog box, click Add Platform.

Developing Java Applications for Intermec Computers 19


5 In the Add Java Platform dialog box, select Java ME CDC Platform Emulator
and click Next.

6 In the Choose Platform Folder screen, browse to the installation folder of the
CrE-ME Developer Kit (default is “C:\Program Files\NSIcom\CrE-ME V4.12”)
and then click Next.

20 Developing Java Applications for Intermec Computers


7 In the Platform Name screen, click Finish.

A new platform entry is added to the CDC node in the Java Platform Manager
dialog box.

Developing Java Applications for Intermec Computers 21


Creating a HelloWorld Project
1 In the NetBeans menu bar, select File > New Project. The New Project dialog
box appears.
2 In the Choose Project screen, choose Java ME in the Categories list, choose CDC
Application in the Projects list, and then click Next.

3 In the Name and Location screen:


a In the Project Name field, enter HelloWorld.
b In the Project Location field, enter the path to (or browse to) the project
location, or accept the default location.
c Uncheck the Create Main Class check box.
d Click Next.

22 Developing Java Applications for Intermec Computers


4 In the Select Platform section, choose pJSCP V4.12 B142.190307 from the Java
Platform list and then click Finish.

Developing Java Applications for Intermec Computers 23


Creating a HelloWorld Class
1 In the Projects window, right-click the HelloWorld project and choose New >
Java Class from the popup menu. The New Java Class dialog box appears.
2 In the Class Name field, enter HelloWorld.
3 In the Package field, enter sample.
4 Click Finish.

Coding the HelloWorld Java Class


Copy the following code to the HelloWorld Java class and click .
package sample;

import java.awt.*;
import java.awt.event.*;

public class HelloWorld extends Frame {


private Label m_LabelHello = new Label("Hello World!");
private Button m_ButtonClose = new Button("Close");

public HelloWorld(String aTitle)


{
super(aTitle);
initComponents();
}

private void initComponents()


{
add(m_LabelHello, BorderLayout.CENTER);
add(m_ButtonClose, BorderLayout.SOUTH);

m_ButtonClose.addActionListener(new ActionListener()
{
// Invoked when the Close button is clicked.

24 Developing Java Applications for Intermec Computers


public void actionPerformed(ActionEvent e)
{
dispose();
System.exit(0);
}
});
}

public static void main(String[] args)


{
HelloWorld hwApp = new HelloWorld("Hello World");
hwApp.setSize(200, 200);
hwApp.setVisible(true);
}
}

This simple application displays the “Hello World!” string in the north of the frame
and a Close button at the south of the frame. Click Close to exit the application.

Building the HelloWorld Project


• In the Projects window, right-click the HelloWorld project and choose Build in
the popup menu.
The build process begins and you see the build results in the Output window. If the
build is successful, you can find HelloWorld.jar in the dist subfolder of the
HelloWorld project folder.

Running HelloWorld in Emulator


You can test the HelloWorld application in the CrEme emulator before deploying
the application to your mobile computer. The emulator can only run a runnable
JAR. A runnable JAR contains a Main-Class attribute in the JAR manifest. The
following will show you how to specify the main class name in the project settings
and run the HelloWorld application in the CrEme emulator.
1 In the Projects window, right-click the HelloWorld project and choose
Properties in the popup menu. The HelloWorld properties dialog box appears.
2 In the Build category choose Running.
3 In the CDC Run tab, click Browse. The Browse Main Classes dialog box appears.
The main classes in the project are shown in the Main classes list.

Developing Java Applications for Intermec Computers 25


4 Choose sample.HelloWorld from the list box and then click Select Main Class.

5 In the HelloWorld properties dialog box, make sure that sample.HelloWorld


appears in the Main Class field of the CDC Run tab.

6 Click OK.
7 In the Projects window, right-click the HelloWorld project and choose Run in
the popup menu. The IDE rebuilds the project and runs the HelloWorld
application in the CrEme emulator.

26 Developing Java Applications for Intermec Computers


Deploying the HelloWorld Application to CrE-ME
If you have CrE-ME 4 on your mobile computer, you can launch the application
directly from NetBeans via ActiveSync.
To run the HelloWorld application in the remote CrE-ME VM
1 In the Projects window, right click the HelloWorld project and choose
Properties from the popup menu. The Hello World properties dialog box
appears.
2 In the navigation pane, choose the Running node in the Build category.
3 Click the CDC Run tab. The Main Class field must be specified. If it is not
already specified, use Browse to select a main class in the project. For the
HelloWorld application, the main class is sample.HelloWorld.

Developing Java Applications for Intermec Computers 27


4 Click the NSIcom tab in the right pane.

5 Check the Run in remote VM check box.


6 By default, the application JAR file (HelloWorld.jar) is deployed to the “\My
Documents\NetBeans Applications” folder on the mobile computer. To deploy
the application to a different location, change information in the Application
Location field.
7 Click OK.
8 In the Projects window, right-click the HelloWorld project and choose Run from
the popup menu. NetBeans builds and deploys the HelloWorld.jar to the mobile
computer and runs the application. The HelloWorld UI appears on your mobile
computer.

Deploying the HelloWorld Application to WEME


Although NetBeans 6.8 supports a deployment option called “Windows Mobile
Deployment (locally attached device)” for CDC projects, the ANT script requires
deploying the JAD file along with the JAR file. Because the CDC project does not
produce the JAD file, the script would fail. Therefore, if you have WEME on your
mobile computer, you need to manually deploy the application. To manually copy
the necessary JAR files and the application shortcut to the mobile computer, see the
next section, “Deploying Applications.”

28 Developing Java Applications for Intermec Computers


Deploying Applications
Deploying your Java application to Intermec mobile computer generally involves
copying the application JAR files and the application shortcut file to the mobile
computer.

Creating the Application Shortcut File


The application shortcut specifies the command line arguments to run an
application. Windows Mobile and CE computers have the following requirements
for the shortcut file:
• The file must have a file extension of .lnk.
• The file must contain only one line of text (up to 255 characters).
• The line begins with nnn# followed by the command line arguments, where nnn
is a number up to 3 digits specifying the number of characters in the command
line. Because the exact number does not seem to matter for Windows Mobile/CE,
use 255# for all shortcuts.
The command line you specify in the shortcut file depends on the JVM. Generally,
you should specify the VM executable followed by the VM options and classpath, the
application main class name, and application arguments. Using the HelloWorld
example we created earlier, the shortcut file should look like the following:
HelloWorld-WEME6-PPRO11.lnk for WEME 6.2 Personal Profile 1.1
255#"\J9\PPRO11\bin\j9.exe" "-jcl:ppro11" "-classpath" "\Program
Files\HelloWorld\HelloWorld.jar" "sample.HelloWorld"
HelloWorld-CrEME4.lnk for CrE-ME 4 Personal Profile 1.0
255#"\windows\CrEme\bin\CrEme.exe" -Of -classpath '\Program
Files\HelloWorld\HelloWorld.jar' sample.HelloWorld
Note: Although you may see multiple lines in the above examples, there is only one
line of text in the shortcut file.

For more information regarding the specific VM options, refer to your JVM
documentation.

Copying Files to the Mobile Computer


To run your application on the mobile computer, you need to copy the necessary
files to the computer. The files usually include the application JAR file, its
dependent library JAR files, and the application shortcut. You may copy the files
from your development machine to the mobile computer via ActiveSync or some
other mechanism.
For the HelloWorld example, you need to copy the HelloWorld.jar to the “\Program
Files\HelloWorld” folder on the mobile computer.

Developing Java Applications for Intermec Computers 29


Note: The file path must match the classpath you specified in the shortcut file. You
may copy the shortcut file anywhere on the device. For ease of maintenance, place
the shortcut file in the same folder as the application JAR files.

Running the Application


On your mobile computer, open File Explorer to browse to the application shortcut.
For WEME, a purple WebSphere icon appears next to the WEME application
shortcut. Tap the shortcut to run the application.
CrE-ME associates the .JAR file and CrE-ME shortcut file with a yellow NSIcom
icon. If the JAR file is a runnable JAR, you can tap the JAR file to launch it in the
CrE-ME JVM. You may also launch the application from a shortcut file containing
CrE-ME specific VM options.

Tip: If you get java.lang.NoClassDefFoundError exception when you run the


application, double-check the classpath and the main class name you specified in
the shortcut. Make sure the JAR files exist in the specified location on the mobile
computer.

Remote Debugging
Remote debugging is possible if the JVM on the mobile computer and the IDE
support Java Platform Debugger Architecture (JPDA). Both the Eclipse and
NetBeans IDEs support remote debugging via JPDA. The IDE debugger can attach
to a remote Java application via JDPA transport.
Although WEME supports remote debugging, CrE-ME 4 does not. This section
walks you through the setup process to debug a Java application running in WEME
from either the Eclipse or NetBeans IDE. The common tasks involved in setting up
remote debugging are as follows:
1 Create an application shortcut that specifies debug options.
2 Deploy the application with the debug shortcut and start the debug session.
3 Set up the IDE JPDA transport to attach to the remote application.
The following sections provide more details for these tasks. Two separate tutorials
are provided for the Eclipse and NetBeans IDEs.

30 Developing Java Applications for Intermec Computers


Creating a Shortcut for Debugging
To start remote debugging, the application needs to be started in debug mode,
which requires additional debug options to be added to the application shortcut.
Using the HelloWorld application created in ‘‘About the Integrated Development
Environment’’ as an example, the following text shows the contents of the shortcut
for debugging (all in one line).
225#"\J9\PPRO11\bin\j9.exe" "-jcl:ppro11" "-Xdebug"
"-Xrunjdwp:transport=dt_socket,server=y,address=8000"
"-classpath" "\Program Files\HelloWorld\HelloWorld.jar"
"sample.HelloWorld"
Note the italicized debug options. The following explains the settings specified in
the “–Xrunjdwp” option. The IDE debugger settings need to match these settings.
• The transport=dt_socket setting specifies the debugger connection will be made via
JPDA socket transport.
• The server=y setting specifies the VM will wait for the remote debugger (IDE) to
attach at the port number specified in the address setting.
• The address=8000 setting specifies the port number (8000) on which the VM is
waiting for the remote debugger (IDE) to attach.

Deploying and Starting a Debug Session


Follow the steps in this section to deploy and launch the HelloWorld application
with the debug shortcut created in the previous section. These steps are similar to
those described in “Deploying Applications.”
1 Save the shortcut created in ‘‘Creating a Shortcut for Debugging’’ in a file
called HelloDbg-WEME6-PPRO11.lnk.
2 Copy both HelloWorld.jar and HelloDbg-WEME6-PPRO11.lnk to the “\Program
Files\HelloWorld” folder on the mobile computer.
3 On the mobile computer, browse to the “\Program Files\HelloWorld” folder. Tap
on HelloDbg-WEME6-PPRO11.lnk to start the debug session.
Since we specified J9.exe in the shortcut, the J9 console appears on the mobile
computer:

Developing Java Applications for Intermec Computers 31


The application does not start until the remote debugger attaches. The next
sections explain how to attach to the debug session from the Eclipse or NetBeans
IDE.

Remote Debugging in Eclipse


This section explains how to remotely debug the HelloWorld application in Eclipse.
Before you begin this section, follow the instructions in ‘‘Creating a Shortcut for
Debugging’’ and “Deploying and Starting a Debug Session.”

Setting Breakpoints
You can set breakpoints in the HelloWorld class before you launch the IDE
debugger. For example, you can set a breakpoint in the HelloWorld class at the
dispose() method in the actionPerformed method of the listener for the Close
button.

Setting and Starting the IDE Debugger


1 In the Package Explorer, choose the HelloWorld application.
2 In the menu bar, choose Run > Debug Configurations. The Debug
Configurations dialog box appears.
3 In the navigation pane, click the Remote Java Application node.
4 Click (above the navigation pane) to create a new configuration.
Configuration settings appear in the right pane. Most of the fields are
automatically populated. You can verify them in the following steps.
5 Specify a name in the Name field if it is not automatically populated.
6 In the Project field, browse to the HelloWorld project if it is not already selected.
7 In the Connection Type list, choose Standard (Socket Attach).
8 In the Host field, enter 169.254.2.1 if your mobile computer is connected to
your PC via ActiveSync. You can specify another IP address as long as it is
reachable from your PC.
Note: For Windows Mobile 5 computers connected via ActiveSync, you need to
double check the USB to PC setting. On the mobile computer, select Start >
Settings > the Connections tab > the USB to PC applet. Make sure the Enable
advanced network functionality check box is checked. For Windows Mobile 6.1
computers, this check box is checked by default. ActiveSync will not work if it is
unchecked.

9 In the Port field, enter 8000.


Note: The port number needs to match what you specified in the address setting
in the –Xrunjdwp option of your application shortcut. For more information, see
“Creating a Shortcut for Debugging” on page 31.

32 Developing Java Applications for Intermec Computers


10 Click Apply to save the settings, or click Debug to save the settings and start
debugging.

As soon as the debugger attaches to the remote VM, the application begins to
run. On the mobile computer, WEME (J9) launches the HelloWorld UI unless
there are breakpoints before the UI is displayed.

Developing Java Applications for Intermec Computers 33


As seen in the following screenshot, the debugger sets a breakpoint at the
dispose() method in the actionPerformed method of the listener for the Close
button. When the Close button is clicked in the HelloWorld UI, the debugger
breaks at the dispose() method.

Remote Debugging in NetBeans


This section walks you through the process of remotely debugging the HelloWorld
application in NetBeans. Before you begin this section, follow the instructions in
‘‘Creating a Shortcut for Debugging’’ and “Deploying and Starting a Debug
Session.”

Setting Breakpoints
You may set some breakpoints in the HelloWorld class before you launch the IDE
debugger. For example, you may set a breakpoint in the HelloWorld class at the
dispose() method in the actionPerformed method of the listener for the Close
button.

34 Developing Java Applications for Intermec Computers


Setting and Starting IDE Debugger
1 In the Projects window, choose the HelloWorld project.
2 In the menu bar, choose Debug > Attach Debugger. The Attach dialog box
appears.
3 In the Debugger drop-down list, choose Java Debugger (JPDA).
4 In the Connector drop-down list, choose SocketAttach (Attaches by socket to
other VMs).
5 In the Host field, enter 169.254.2.1 if your mobile computer is connected to
your PC via ActiveSync. You may specify another IP address as long as it is
reachable from your PC.
Note: For Windows Mobile 5 computers connected via ActiveSync, you need to
double check the USB to PC setting. On the mobile computer, select Start >
Settings > the Connections tab > the USB to PC applet. Make sure the Enable
advanced network functionality check box is checked. For Windows Mobile 6.1
computers, this check box is checked by default. ActiveSync will not work if it is
unchecked.

6 In the Port field, enter 8000.


Note: The port number needs to match what you specified in the address setting
in the –Xrunjdwp option of your application shortcut. For more information, see
“Creating a Shortcut for Debugging” on page 31.

7 Click OK to start debugging.

Developing Java Applications for Intermec Computers 35


As soon as the debugger attaches to the remote VM, the application runs. On the
mobile computer, WEME (J9) launches the HelloWorld UI, unless there are
breakpoints before the UI is displayed.

As seen in the next screenshot, it sets a breakpoint at the dispose() method in the
actionPerformed method of the listener for the Close button. When the Close
button is clicked in the HelloWorld UI, the debugger breaks at the dispose() method.

36 Developing Java Applications for Intermec Computers


Accessing Databases Using JDBC
The JDBC API enables Java applications to access SQL-based databases or tabular
data sources. JSR 169 defines a JDBC Optional Package for Java ME CDC. Note that
JSR 169 only provides a subset of the JDBC 4.0 API in Java SE 6. WEME 6.2 includes
the JDBC optional package that implements JSR 169. CrE-ME also has support for
JDBC but it is not clear whether it implements JSR 169.
Java SE supports two ways to connect to the database via the DriverManager class or
the DataSource interface. JSR 169 only supports the DataSource interface. The code
will work in both WEME and CrEme if you use a vendor specific DataSource object
to connect to the database.
Note: Currently the database vendors such as IBM and Oracle only support JDBC
drivers to access local databases, and provide data synchronization between the local
and the remote server databases.

JDBC Sample Application


This sample application connects to an IBM DB2 Everyplace (DB2e) database via
the com.ibm.db2e.jdbc.DB2eDataSource object that implements the
javax.sql.DataSource interface. The URL string “jdbc:db2e:mydb” identifies a data
source. Note that the URL format may be vendor specific.
package sample;
import java.sql.*;

public class JDBCSample {


public static void main(String[] args)
{
String url = "jdbc:db2e:mydb";
Connection con = null;
Statement st = null;
ResultSet rs = null;

try
{
// DB2eDataSource is in db2ejdbc.jar which is included in the
// DB2e installation CAB file.
com.ibm.db2e.jdbc.DB2eDataSource ds = new com.ibm.db2e.jdbc.DB2eDataSource();
ds.setUrl(url);
con = ds.getConnection();
st = con.createStatement();

// Creates a table called INVENTORY.


st.executeUpdate("CREATE TABLE INVENTORY (ITEM VARCHAR(32), QTY INT)");
System.out.println("*** Created table: INVENTORY");

// Inserts records to the INVENTORY table.


st.executeUpdate("INSERT INTO INVENTORY VALUES ('9780201',3)");
st.executeUpdate("INSERT INTO INVENTORY VALUES ('9780672',10)");
System.out.println("*** Inserted two records");

// Queries the INVENTORY table.


rs = st.executeQuery("SELECT * FROM INVENTORY");
System.out.println("*** Query results:");

Developing Java Applications for Intermec Computers 37


while (rs.next())
{
System.out.print("ITEM=" + rs.getString(1) + ", ");
System.out.println("QTY=" + rs.getInt(2));
}

// Since this is only an example, delete the INVENTORY table.


st.executeUpdate("Drop table INVENTORY");
System.out.println("*** Deleted table: INVENTORY");
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
// Releases resources.
try {
if (rs != null) rs.close();
} catch (Exception e) {e.printStackTrace();}

try {
if (st!= null) st.close();
} catch (Exception e) {e.printStackTrace();}

try {
if (con != null) con.close();
} catch (Exception e) {e.printStackTrace();}
}
}
}

Building the Sample


To build this sample, follow the rules in “About the Integrated Development
Environment” on page 10. Note that the JDBCSample refers to the
com.ibm.db2e.jdbc.DB2eDataSource class which is in db2ejdbc.jar. The
db2ejdbc.jar file is included in the DB2e installation. You need to add db2ejdbc.jar
as an external JAR to the IDE project, or include db2ejdbc.jar in the classpath if you
use the javac compiler from command line.

Running the Sample


To deploy and run this sample on the mobile computer, see the instructions in
“Deploying Applications” on page 29. The application shortcut to run this
sample in WEME may look like the following:
255#"\J9\PPRO11\bin\j9.exe" "-jcl:ppro11" -
Djava.library.path=\Windows -classpath "\Program
Files\JDBCSample\JDBCSample.jar;\Windows\db2ejdbc.jar"
"sample.JDBCSample"
Note that it specifies the “-Djava.library.path=\Windows” option which is required
in order for WEME to load the DB2e’s native DLLs. This shortcut assumes the
JDBCSample.class is packaged in JDBCSample.jar which is located in the “\Program
Files\JDBCSample” folder on the mobile computer.

38 Developing Java Applications for Intermec Computers


This sample application simply outputs to the console. The J9 console displays the
following text when you run the application.

You can also run this sample in CrE-ME. The following is a shortcut for CrE-ME 4:
255#"\windows\CrEme\bin\CrEme.exe" -Of -classpath '\Program
Files\JDBCSample\JDBCSample.jar;\Windows\db2ejdbc.jar'
sample.JDBCSample
Note: The “-Of” option specifies the output will be redirected to jscpout.txt located
at the root folder of the mobile computer.

Adapting the Sample for Other DBMS


You can easily change the DataSource related code in the JDBCSample to connect to
a different DBMS. The following is the code snippet to connect to an Oracle
Database Lite database.
String url = "jdbc:polite:polite";
oracle.lite.poljdbc.POLJDBCDataSource ds = new
oracle.lite.poljdbc.POLJDBCDataSource();
ds.setUrl(url);
ds.setUser("SYSTEM");
ds.setPassword("MANAGER");
It instantiates the oracle.lite.poljdbc.POLJDBCDataSource object and sets up the
data source url “jdbc:polite:polite”. It also sets the username and password to access
the database. Once you made these changes, the rest of the code in JDBCSample
should work fine with the Oracle Lite database.

Developing Java Applications for Intermec Computers 39


Developing a Web Services Client
Web services are APIs that can be accessed over a network regardless of systems and
languages, and are best used to integrate heterogeneous systems. Although it is
beyond the scope of this document to discuss when or why you should use this
technology, if you decide to deploy web services this section shows you how to
develop a mobile application to consume web services.
The web services client development usually involves generating stub classes from
the Web Services Definition Language (WSDL). The stub classes allow the client to
access the web services APIs via Java classes and methods and hide the complexity of
encoding and decoding the SOAP messages. Although there are a lot of tools that
generate web services stubs, we need to consider the web services supported on the
mobile computers.
JSR 172 is the specification that defines an optional package for Java ME
applications to access web services. Currently both WEME 6.2 and CrE-ME 4.12 do
not provide implementation for JSR 172. An implementation of JSR 172 that is
compatible with Java ME CDC is required to support the web services development
and deployment.
Sun Microsystems, now a subsidiary of Oracle Corporation, implemented JSR 172
in its Java Wireless Toolkit 2.5.2 and Java ME SDK 3.0. Both implementations target
Java ME CLDC/MIDP. Although the Java Wireless Toolkit has been integrated into
the Java ME SDK 3.0, jsr172_1.0.jar in Java ME SDK 3.0 causes runtime errors
during testing with WEME 6.2. Because the Java Wireless Toolkit implementation of
JSR 172 works better with CDC, Intermec recommends that you use Java Wireless
Toolkit 2.5.2. To follow the tutorials in this section, you need to download and
install sun_java_wireless_toolkit-2.5.2_01-win.exe from the Sun Java Wireless
Toolkit 2.5.2_01 for CLDC Download web site.
The following sections will walk you through the development process of creating a
web services client to consume a web service hosted by www.webservicex.net. Two
separate tutorials are offered for developing in Eclipse or NetBeans.
Note: The web services example used in this section was tested against WEME 6.2
and CrE-ME 4.12. Although it seems to get the expected result, it takes a long time
(several minutes) for the web service call to return a response when running in CrE-
ME. It only takes a few seconds to get the response in WEME.

Developing a Web Services Client in Eclipse


There is no Eclipse plug-in that supports Web Services development for Java ME
CDC. This tutorial uses the Sun Java Wireless Toolkit to generate the web services
stubs and import them into Eclipse. If you have not already installed Java Wireless
Toolkit, download sun_java_wireless_toolkit-2.5.2_01-win.exe from the Sun Java
Wireless Toolkit 2.5.2_01 for CLDC Download web page and install it on your
PC.

40 Developing Java Applications for Intermec Computers


The following is a summary of the development process.
1 Create an Eclipse Java project and add the web services JAR files from the Java
Wireless Toolkit as external JARs.
2 Adjust the project compiling source level.
3 Use the Sun Java Wireless Toolkit to generate the web services stubs.
4 Import the generated stubs to the Eclipse project.
5 Create a Java class to call the web services API via the stub.
6 Export the application class files to a JAR.
7 Deploy the application to an Intermec mobile computer.

Creating a StockQuoteWTK Java Project


1 In the Eclipse IDE, select File > New > Project.
2 In the New Project dialog box, choose Java Project and click Next.

Developing Java Applications for Intermec Computers 41


3 In the Project name field, enter StockQuoteWTK and click Next.

4 In the Java Settings screen, choose the Libraries tab and click Add External
Jars. The JAR Selection dialog box appears. Browse to the lib subfolder of the
Java Wireless Toolkit installation folder.

42 Developing Java Applications for Intermec Computers


5 Choose j2me-ws.jar and j2me-xmlrpc.jar and click Open.

The JARs and class folders on the build path list in the Libraries tab now
includes the JARs you selected.

6 Click Finish to save the project settings.

Developing Java Applications for Intermec Computers 43


Setting the Project Compiling Source Level
1 In the Package Explorer, right click the StockQuoteWTK project and choose
Properties in the popup menu. The Properties for StockQuoteWTK dialog box
appears.
2 In the navigation pane, choose Java Compiler.
3 Uncheck the Use compliance from execution environment ‘JavaSE-1.6’ on
the Java Build Path check box.
4 Uncheck the Use default compliance settings check box.
5 Set both Generated .class files compatibility and Source compatibility to 1.4.
This ensures the generated byte code will be compatible with WEME and CrE-
ME 4.
6 Click OK to accept the changes.

Generating Web Services Stubs


This tutorial uses the Sun Java Wireless Toolkit 2.5.2 to generate the web services
stubs. There should be a shortcut on the desktop for the Wireless Toolkit. If you
don’t see the desktop shortcut, browse to the “bin” subfolder of the Wireless Toolkit
installation folder and run ktoolbar.exe.

44 Developing Java Applications for Intermec Computers


This screen appears after the Wireless Toolkit is started:

To generate the web services stubs


1 Click New Project. The New Project dialog box appears.

2 In the Project Name field, enter StockQuote and click Create Project. The API
Selection dialog box appears.

Developing Java Applications for Intermec Computers 45


3 Click OK.
4 In the menu bar, choose Project > Stub Generator.

5 In the Stub Generator Dialog, do the following:


a In the WSDL Filename or URL field, enter http://
www.webservicex.net/stockquote.asmx?wsdl.
b In the Output Package field, enter test.stub. This field specifies the
package name that the stub classes will be generated under.
c Click OK.
Note: When the stub generation is successfully completed, the generated Java
classes appear in the indicated Output Path.

46 Developing Java Applications for Intermec Computers


6 Locate the generated Java classes. We will import these classes to Eclipse later.

Importing Generated Stub Classes to Eclipse


1 In the Eclipse Package Explorer, right-click the StockQuoteWTK project and
choose Import in the popup menu. The Import dialog box appears.
2 In the Select an import source list, choose General > File System and click
Next.

Developing Java Applications for Intermec Computers 47


3 In the File system screen:
a Click Browse and browse to the folder where the stubs were generated. This
example selects the src folder that contains the test\stub subfolder. Make
sure the src checkbox is checked.
b In the Into folder entry field, type StockQuoteWTK\src.
c Click Finish.

If the stub classes are successfully imported, they are included under the src folder of
the StockQuoteWTK project node.

48 Developing Java Applications for Intermec Computers


Creating a Java Class to Call the Web Services API
1 In the Eclipse Package Explorer, right-click the StockQuoteWTK project and
choose New > Class from the popup menu. The New Java Class dialog box
appears.
2 In the Name field, enter StockQuoteMain.
3 Check the public static void main(String[] args) check box to generate the
main method.
4 Click Finish.

Developing Java Applications for Intermec Computers 49


Source Code for StockQuoteMain
In the source code viewer of StockQuoteMain, enter the following code. Click to
save the changes.
package test;
import test.stub.*;

/**
* Simple class to test the web services stub generated by Sun Java
* Wireless Toolkit 2.5.2.
*/
public class StockQuoteMain {

/**
* @param args
*/
public static void main(String[] args)
{
String sSymbol = null; // Stock symbol
if (args.length > 0)
{
sSymbol = args[0];
}
else
{
sSymbol = "IN"; // Default to Intermec symbol.
}

try
{
System.out.println("Making web services call...");
StockQuoteSoap_Stub stub = new StockQuoteSoap_Stub();
String sQuoteXML = stub.getQuote(sSymbol);
System.out.println("sQuote=" + sQuoteXML);
// Get the value between <Last> and </Last>
int indStart = sQuoteXML.indexOf("<Last>");
int indEnd = sQuoteXML.indexOf("</Last>");
if (indStart >= 0 && indEnd >= 0)
{
String sLatestValue = sQuoteXML.substring(
indStart+6, indEnd);
System.out.println("Quote=" + sLatestValue);
}
else
{
System.out.println("Missing <Last> tag in response");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

50 Developing Java Applications for Intermec Computers


Programming Notes
The stock symbol is passed in as the first program argument. The default is “IN” if
not specified. It calls the StockQuoteSoap_Stub.getQuote method to get the
current quote. Note that this method returns an XML string. You can use the kXML
library to parse the XML. The above code uses methods in String to retrieve the
value between the <Last> and </Last> tags.

Exporting Classes to StockQuoteWTK.jar


1 In the Eclipse Package Explorer, right-click the src folder under the
StockQuoteWTK project and choose Export from the popup menu. The Export
dialog box appears.
2 In the Select an export destination list, choose Java > JAR file and click Next.

3 In the JAR File Specification screen, click Browse. The Save As dialog box
appears.

Developing Java Applications for Intermec Computers 51


4 Browse to the StockQuoteWTK project folder, enter StockQuoteWTK.jar in
the File name field, and click Save.

5 The JAR file list in the JAR File Specification screen now shows
“StockQuoteWTK/StockQuoteWTK.jar”. This specifies that the output JAR file,
StockQuoteWTK.jar, will be created under the StockQuoteWTK project folder.

6 Click Finish to generate the JAR file.

52 Developing Java Applications for Intermec Computers


Deploying the Web Services Client to the Mobile
Computer
This section describes how to deploy the StockQuoteWTK web services client
application to the mobile computer. It also follows the guidelines described in
“Deploying Applications” on page 29.

Creating an Application Shortcut


Create a WEME or CrE-ME shortcut like the following:
StockQuoteWTK-WEME6-PPRO11.lnk for WEME 6.2 Personal Profile 1.1
255#"\J9\PPRO11\bin\j9.exe" "-jcl:ppro11" "-classpath"
"\StockQuoteWTK\j2me-ws.jar;\StockQuoteWTK\j2me-
xmlrpc.jar;\StockQuoteWTK\StockQuoteWTK.jar" test.StockQuoteMain
StockQuoteWTK-CrEME4.lnk for CrE-ME 4 Personal Profile 1.0
255#"\windows\CrEme\bin\CrEme.exe" -Of -classpath
'\StockQuoteWTK\j2me-ws.jar;\StockQuoteWTK\j2me-
xmlrpc.jar;\StockQuoteWTK\StockQuoteWTK.jar' test.StockQuoteMain

Copying Files to the Mobile Computer


1 In the root directory of the mobile computer, create a folder called
StockQuoteWTK.
2 Copy StockQuoteWTK.jar (as generated in ‘‘Exporting Classes to
StockQuoteWTK.jar’’) to the mobile computer \StockQuoteWTK folder.
3 Depending on the JVM you are using, copy either StockQuoteWTK-WEME6-
PPRO11.lnk or StockQuoteWTK-CrEME4.lnk to the mobile computer
\StockQuoteWTK folder.
4 On the PC, browse to the lib subfolder of the Java Wireless Toolkit installation
folder, and copy j2me-ws.jar and j2me-xmlrpc.jar to the mobile computer
\StockQuoteWTK folder.

Developing Java Applications for Intermec Computers 53


5 In the ActiveSync window, click Explore and browse to the \StockQuoteWTK
folder, where you should see the following files:

6 On the Intermec mobile computer, use File Explorer to browse to the


\StockQuoteWTK folder.
7 To run the application with WEME, tap the shortcut StockQuoteWTK-WEME6-
PPRO11.lnk (with the purple WebSphere icon next to it). The stock quote value
is displayed in the J9 Console.

To run the application with CrE-ME 4, tap the shortcut StockQuoteWTK-


CrEME4.lnk. The result will be outputted to jscpout.txt located at the root folder of
your mobile computer.
Note: It may take several minutes for the web services call to return a response when
running in CrE-ME 4.

Developing a Web Services Client in NetBeans


Developing a web services client application in NetBeans is easier than in Eclipse
because you can rely on the Java ME plug-in to generate the web services stubs. If
you have not already installed the Java ME plug-in, follow the instructions in
‘‘Installing the Java ME Plug-in’’ to install it.

54 Developing Java Applications for Intermec Computers


The Java ME plugin for NetBeans 6.8 includes Java ME SDK 3.0. As noted in the
beginning of ‘‘Developing a Web Services Client’’, the jsr172_1.0.jar file in Java
ME SDK does not work in CDC. Therefore, we will use the plug-in only to generate
the stubs. At runtime, we will use the JAR files in Java Wireless Toolkit 2.5.2. If you
have not already installed Java Wireless Toolkit, download and install
sun_java_wireless_toolkit-2.5.2_01-win.exe from the Sun Java Wireless Toolkit
2.5.2_01 for CLDC Download web site.
The following is a summary of the development process.
1 Create a NetBeans Java project.
2 Add web services JAR files from the Java Wireless Toolkit as external JARs.
3 Generate the web services stubs.
4 Create a Java class to call the web services API via the generated stub.
5 Build the application.
6 Deploy the application to an Intermec mobile computer.

Creating the StockQuoteWTK Java Project


1 In NetBeans, choose File > New Project. The New Project dialog box appears.
2 In the Categories list, choose Java ME.
3 In the Projects list, click CDC Application and then click Next.

Developing Java Applications for Intermec Computers 55


4 In the Name and Location screen:
a In the Project Name field, enter StockQuoteWTK.
b In the Project Location field, enter the path to the project location, or click
Browse to browse to the project location. To accept the default location,
continue with the next step.
c Uncheck the Create Main Class checkbox.
d Click Next.

5 In the Select Platform screen, select pJSCP V4.12 B142.190307 from the Java
Platform drop-down list and then click Finish.

56 Developing Java Applications for Intermec Computers


Adding Web Services JAR Files
Although we can use the Java ME plugin to generate the web services stubs, the
CrEme emulator platform we use to compile this project does not have built-in
support for the APIs in JSR 172. Therefore, we need to add additional libraries that
implement JSR 172. We will add two libraries, j2me-ws.jar and j2me-xmlrpc.jar from
Java Wireless Toolkit 2.5.2 to the StockQuoteWTK project. These libraries allow the
application to be successfully built in NetBeans, and they are included in the
application JAR file as the build result.
To add web services JAR files to the StockQuoteWTK project
1 In the Projects window, right-click the StockQuoteWTK project and choose
Properties in the popup menu.
2 In the Category list, choose Build > Libraries and Resources.
3 Click Add JAR/Zip.
4 In the Add Jar or Zip file dialog box, browse to the lib subfolder of the
installation folder of Java Wireless Toolkit 2.5.2.

5 Choose both j2me-ws.jar and j2me-xmlrpc.jar and click Open.

Developing Java Applications for Intermec Computers 57


6 The Libraries and Resources list in the StockQuoteWTK project settings screen
now includes the JAR files you added.

Generating Web Services Stubs


1 In the Projects window, right-click the StockQuoteWTK project and choose New
> Java ME Web Service Client from the popup menu. The New Java ME Web
Service Client dialog box appears.
2 Make sure the Running Web Service button is selected (should be the default).
3 In the WSDL URL field, enter http://www.webservicex.net/
stockquote.asmx?WSDL and click Retrieve WSDL.
4 After NetBeans successfully validates the WSDL, click Finish.

58 Developing Java Applications for Intermec Computers


Two Java classes, StockQuote.java and StockQuote_Stub.java, are generated with
the package name “stockquote”.

Creating a Java Class to Call the Web Services API


1 In the Projects window, right-click the StockQuoteWTK project and choose New
> Java Class from the popup menu. The New Java Class dialog box appears.
2 In the Class Name field, enter StockQuoteMain.
3 In the Package field, enter stockquote. This is the package name the stub
classes were generated under. We will use the same package name so we don’t
need to import this package.
4 Click Finish.

Copy the following code to the StockQuoteMain Java class and click to save it.
package stockquote;

public class StockQuoteMain {


public static void main(String[] args)
{
String sSymbol = null; // Stock symbol
if (args.length > 0)
{
sSymbol = args[0];
}
else
{
sSymbol = "IN"; // Default to Intermec symbol.
}

try
{
System.out.println("Making web services call...");
StockQuote_Stub stub = new StockQuote_Stub();

Developing Java Applications for Intermec Computers 59


String sQuoteXML = stub.getQuote(sSymbol);
System.out.println("sQuote=" + sQuoteXML);

// Get the value between <Last> and </Last>


int indStart = sQuoteXML.indexOf("<Last>");
int indEnd = sQuoteXML.indexOf("</Last>");
if (indStart >= 0 && indEnd >= 0)
{
String sLatestValue =
sQuoteXML.substring(indStart+6, indEnd);
System.out.println("Quote=" + sLatestValue);
}
else
{
System.out.println("Missing <Last> tag in response");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

Programming Notes
The stock symbol is passed in as the first program argument. The default is “IN” if
not specified. It calls the StockQuote_Stub.getQuote method to get the current
quote. Note that this method returns an XML string. You can use the kXML library
to parse the XML. The code uses methods in String to retrieve the value between the
<Last> and </Last> tags.

Building the StockQuoteWTK Project


In the Projects window, right click on the StockQuoteWTK project and select Build
in the popup menu. The build process begins and you see the build results in the
Output window. If the build is successful, you can find StockQuoteWTK.jar in the
dist subfolder of the StockQuoteWTK project folder.

Deploying StockQuoteWTK onto Mobile Computer


This section describes how to deploy the StockQuoteWTK web services client
application to the mobile computer, following the guidelines described in
“Deploying Applications.”

Creating an Application Shortcut


You may create a WEME or CrE-ME shortcut like the following:
StockQuoteWTK-WEME6-PPRO11.lnk for WEME 6.2 Personal Profile 1.1
255#"\J9\PPRO11\bin\j9.exe" "-jcl:ppro11" "-classpath"
"\StockQuoteWTK\StockQuoteWTK.jar" stockquote.StockQuoteMain
StockQuoteWTK-CrEME4.lnk for CrE-ME 4 Personal Profile 1.0
255#"\windows\CrEme\bin\CrEme.exe" -Of -classpath
'\StockQuoteWTK\StockQuoteWTK.jar' stockquote.StockQuoteMain

60 Developing Java Applications for Intermec Computers


Copying Files to the Mobile Computer
1 Create a folder called StockQuoteWTK under the root directory of the mobile
computer.
2 Copy StockQuoteWTK.jar in the dist subfolder of the StockQuoteWTK project
folder to the mobile computer \StockQuoteWTK folder.
3 Depending on the JVM you use, copy either StockQuoteWTK-WEME6-
PPRO11.lnk or StockQuoteWTK-CrEME4.lnk to the mobile computer
\StockQuoteWTK folder.
4 On the Intermec mobile computer, use File Explorer to browse to the
\StockQuoteWTK folder.
5 To run the application with WEME, tap the shortcut StockQuoteWTK-WEME6-
PPRO11.lnk (with the purple WebSphere icon next to it) to run the application.
The stock quote value is displayed in the J9 Console.

To run the application with CrE-ME 4, tap on the shortcut StockQuoteWTK-


CrEME4.lnk. The result is sent to jscpout.txt located at the root folder of your
mobile computer.
Note: It may take several minutes for the web services call to return a response when
running in CrE-ME 4.

Developing Java Applications for Intermec Computers 61


Glossary
AWT (Abstract Window Toolkit)
AWT provides a basic set of graphical user interface (GUI) components that were
implemented using native-platform versions of the components.

CDC (Connected Device Configuration)


CDC is a specification for a Java ME configuration. It targets network-connected
devices that have more memory and processing power such as high-end personal
digital assistants (PDAs).

CLDC (Connected Limited Device Configuration)


CLDC is a specification for a Java ME configuration. It targets resource-constrained
devices like mobile phones and entry level personal digital assistants (PDAs).

CrE-ME or CrEme
CrE-ME or CrEme (by NSIcom) is a Java runtime environment for mobile
computers. CrE-ME version 4 implements Java ME CDC Personal Profile 1.0.

IDE (Integrated Development Environment)


An IDE brings all tools needed for programming such as source code editor,
compiler, debugger, etc. in one environment to facilitate software development.

IDL (Intermec Developer Library)


IDL provides developers with tools and resources to develop applications for
Intermec mobile computers and RFID readers.

IDL Resource Kits


IDL Resource Kits provide C/C++, .NET, Java and Web APIs for building
applications that take full advantage of features integrated into Intermec mobile
computers, RFID readers and peripherals.

JDK (Java SE Development Kit)


JDK is the software development kit from Sun Microsystems to develop Java
applications and applets for Java Platform Standard Edition (Java SE). The JDK
version numbering scheme changes in version 1.5. Version 1.5 becomes JDK 5, and
1.6 becomes JDK 6.

Java EE (Java Platform, Enterprise Edition)


Java EE is a Java platform for enterprise Java computing.

Java ME (Java Platform, Micro Edition)


Java ME is a Java platform designed for mobile devices and embedded systems.

Java SE (Java Platform, Standard Edition)


Java SE is a widely used Java platform for developing and deploying Java
applications on desktops and servers.

62 Developing Java Applications for Intermec Computers


JCE (Java Cryptography Extension)
JCE provides a framework and implementation for encryption, key generation, key
agreement, and message authentication code (MAC) generation services. The CDC
Foundation Profile 1.1 specification, JSR 219, includes the JCE optional package.

JDBC (Java Database Connectivity)


JDBC is an API that enables Java applications to access SQL-based databases or
tabular data sources.

JNI (Java Native Interface)


JNI is a standard programming interface that allows Java methods to invoke native
methods implemented in C or vice versa.

JPDA (Java Platform Debugger Architecture)


JPDA provides the infrastructure to build end-user debugger applications for Java
platforms.

JSR (Java Specification Request)


JSR is a formal document that describes proposed specifications and technologies
to be added to the Java platform.

JSSE (Java Secure Socket Extension)


JSSE is a set of packages that enables secure internet communications. The CDC
Foundation Profile 1.1 specification, JSR 219, includes the JSSE optional package.

MIDP (Mobile Information Device Profile)


MIDP is a specification that defines a profile to extend the Java ME CLDC.

Personal Profile
Personal Profile is a specification that defines a profile to extend the Java ME CDC.
It has full AWT 1.1 support and includes all the APIs in the other CDC profiles,
Foundation Profile and Personal Basis Profile.

RMI (Java Remote Method Invocation)


RMI is an API that allows a Java object to invoke methods on an object running in
another JVM. JSR 66 defines the RMI optional package for Java ME.

SOAP (Simple Object Access Protocol)


SOAP is an XML-based messaging protocol for exchanging structured information
in a distributed environment. SOAP is used to invoke web services.

WEME (WebSphere Everyplace Micro Environment)


WEME (by IBM) is a Java runtime environment for mobile computers that
implements Java Platform, Micro Edition (Java ME). The current WEME version
Intermec resells, WEME 6.2, implements Java ME CDC/Personal Profile 1.1.

WSDL (Web Services Definition Language)


WSDL is an XML-based language to describe how to access a web service and what
operations it performs.

Developing Java Applications for Intermec Computers 63


Worldwide Headquarters
6001 36th Avenue West
Everett, Washington 98203
U.S.A.
tel 425.348.2600
fax 425.355.9551
www.intermec.com
© 2010 Intermec Technologies
Corporation. All rights reserved.

You might also like