Contents Previous Next Index

Chapter   3

Operating with KToolbar


KToolbar is a minimal development environment for developing MIDlet suites. From the KToolbar, you can:

To run the KToolbar:

Navigating in KToolbar

You can navigate through KToolbar windows (the main window, Profiling, Memory Monitor, and Network Monitor windows) using the Tab and arrow keys. Mnemonics on menus and buttons provide you with alternative means to initiating commands. A mnemonic is the underlined letter that corresponds to the keyboard key to press in conjunction with the Alt key to activate a command or to navigate to a component in the window.

You can press the Tab key to bring the focus to a particular component of a window and then use the arrow keys to manipulate that component.

KToolbar Projects

A KToolbar project is associated with a MIDlet suite. The project contains the suite’s source, resource, and binary files, as well as the JAD and manifest files that contain the suite’s attributes.

Project files are located in project subdirectories under the Wireless Toolkit’s installation directory, {j2mewtk.dir}. The following table shows how files are organized within the directory for the project, {project.name}:

TABLE 1  –  Project File Organization
Directory
Description
{j2mewtk.dir}\apps\{project.name}
Contains all source, resource, and binary files of the project
{j2mewtk.dir}\apps\{project.name}\bin
Contains the JAR, JAD, and unpacked manifest files.
{j2mewtk.dir}\apps\{project.name}\lib
Contains external class libraries, in JAR or ZIP format for a specific project.
{j2mewtk.dir}\apps\{project.name}\res
Contains all the resource files.
{j2mewtk.dir}\apps\{project.name}\src
Contains all the source files.
{j2mewtk.dir}\apps\lib
Contains external class libraries, in JAR or ZIP format for all KToolbar projects.


Note – Adding external class libraries to a project increases the size of the MIDlet suite’s JAR file. Large JAR files take longer to load onto a device, and might be unusable on devices with low memory.

Creating a New Project

To create a new project:

  1. Choose File -> New Project from the menu or click New Project on the toolbar.
  2. The New Project dialog appears.

  3. Type the name of the project in the Project Name field, and the name of the main MIDlet class in the MIDlet Class Name field.
  4. For example, you might call the project, newproject, and the MIDlet class might be myTest.Hello.

  5. Click Create Project.
  6. The main window’s title changes to include the name of the new project, as shown in FIGURE 3. The Project Settings API Selection tab is displayed as shown in FIGURE 4.

    Project creation output statements in KToolBar main window.

    FIGURE 3  –  Console Output After Creating a Project

    The console indicates where to place your source, resource, and library files. The locations are consistent with the project file organization outlined in TABLE 1.

    Project Settings dialog with API Selection tab and JTWI target platform selected

    FIGURE 4  –  Settings API Selection Tab

  7. Select the Target Platform.
  8. The target platform defines the set of APIs that are used for developing your MIDlet.

    The target platform may be one of the following:

    The project settings information and tabs change based on the selection you choose for the target platform. Some project settings are not applicable for a selected target platform. For example, the MIDP 1.0 target platform does not support Push Registry or Permissions, therefore the tabs are disabled. All project settings tabs are updated with information relevant to your selection. For example, if you selected the JTWI target platform, the MicroEdition-Profile value is updated in the Required tab.

  9. Select the Profiles, Configurations, and Additional/Optional APIs for your project and click OK.

Opening an Existing Project

To open an existing project:

  1. Choose File -> Open Project from the menu or click Open Project on the toolbar.
  2. The Open Project dialog appears with a list of projects.

  3. Double-click the project, or choose the project and click Open Project.
  4. The main window’s title changes to include the name of the project.

Editing MIDlet Suite Attributes

This section explains how to use the project settings dialog to modify a MIDlet suite’s attributes. Use the project settings dialog box, shown in FIGURE 4, to edit a MIDlet suite’s project settings.

To open the Settings dialog box for the current project:

Modifying MIDlet Suite Attributes

To change a required, optional, or user-defined MIDlet suite attribute:

  1. Click the Required, Optional, or User Defined tab.
  2. The required, optional, or user-defined attributes and their current values are displayed depending on which tab you clicked.

    Project creation output statements in KToolBar main window.

    FIGURE 5  –  Project Settings Required Tab Dialog

  3. Click on an attribute’s value field, make your changes, and press Enter.

For more information about the attributes themselves, see Appendix A, "MIDlet Attributes.”

Modifying User-Defined Attributes

You can also add or remove user-defined attributes through the User Defined tab in the Project Settings dialog box in the J2ME Wireless Toolkit.

Adding User-Defined Attributes

To add a user-defined attribute:

  1. Click Add.
  2. The Add Property dialog appears.

  3. Enter the name of the attribute and click OK.
  4. The Add Property dialog disappears, and a new entry is created for the attribute.


    Note – Do not use the prefix “MIDlet-” for a user-defined attribute. This format is reserved for system-defined MIDlet attributes.
  5. Click the attribute’s value field, enter a value, and press Enter.

Removing User-Defined Attributes

To remove a user-defined attribute:

Modifying MIDlet-Specific Attributes

You can edit, add, or remove user-defined attributes through the MIDlets tab in the project settings dialog box in the J2ME Wireless Toolkit.

To edit an individual MIDlet’s name, icon, and class:

  1. Choose the MIDlet and click Edit.
  2. Make your changes in the Enter MIDlet Details dialog box and click OK.

Adding MIDlet-Specific Attributes

To add a MIDlet-specific attribute:

  1. Click Add.
  2. Enter the MIDlet’s name and attributes in the Enter MIDlet Details dialog box, and click OK.
  3. A new entry is created for the MIDlet.

Removing MIDlet-Specific Attributes

To remove a set of MIDlet-n attributes specific to a particular MIDlet:

Adding MIDlets

To add a MIDlet to your project:

  1. Select Add.
  2. Enter the MIDlet Details and click OK.
  3. The new MIDlet is added with a consecutive key.

Changing the Order of the MIDlets

To change the order of the MIDlets in the suite (that is, the order in which they are listed when you launch the suite):

Adding a Push Registry

You can add and remove push registry attributes for MIDlets with the Push Registry tab in the project settings dialog box:

Display of push registration in Project Settings dialog box.

FIGURE 6  –  Sample of a Push Registry

To register a MIDlet in the Push Registry:

  1. Choose Project -> Settings and click on the Push Registry tab.
  2. Click Add and provide the following information in the Enter MIDlet Details dialog box, then click OK:

The Key is the Push registration attribute name and is automatically generated. A MIDlet suite can have multiple push registrations. Each key (registration) designation is unique and of the form MIDlet-Push-<n>, where <n> begins at 1 and is incrementally increased with each registration. MIDlet Push registration information is stored in the MIDlet suite’s JAD file.

By selecting a key and clicking Edit or Remove, you can change the attributes for the selected key or remove it from the registry.

Note that the push registry functionality is only available when you are running in OTA provisioning mode. For more information on running using OTA provisioning in the Wireless Toolkit environment, see Chapter 2, "Developing and Running Applications.”

Adding API Permissions

For your MIDlet suite to operate, it might need to access certain protected APIs. A request for permission to access these APIs is required. You can set the MIDlet-Permissions and MIDlet-Permissions-Opt attributes from the Permissions panel of the Project Settings dialog box.

To specify which APIs the current MIDlet suite can access:

  1. Choose Project -> Settings and click the Permissions tab.
  2. Click Add for either required (MIDlet-Permissions) or optional (MIDlet-Permissions-Opt).
  3. The Permission API selection dialog box opens from which you can select the API permission to add. Shift+click to add multiple APIs at once.

    Example of Permissions Selections dialog box showing list of javax.microedition.io APIs.

    FIGURE 7  –  API Permissions Selection Dialog Box

Permissions have the same naming structure as a Java class. For instance, javax.microedition.io.Connector.http is the permission for the HTTP protocol. To make use of the Push Registry, you must have permission to access the Push Registry API, javax.microedition.io.PushRegistry.

Removing API Permissions

To remove API permissions:

Compiling and Preverifying a Project

The KToolbar compiles and preverifies source code in one sequence.

To compile and preverify your source code:

The classpath for compilation and preverification are based on the project's API selection. The preverifier is selected based on the version of the CLDC selected by the user. Compilation and preverification, can also be performed from the command line. For more information, see Appendix D, "Command Line Utilities.”

Running a Project Locally

Once you have built your application, you can run it immediately from the KToolbar.

To run the current MIDlet suite in the Emulator using the KToolbar:

  1. (Optional) Use the Device menu to select the device to be emulated.
  2. The list displays the devices available for the loaded application.

  3. Choose Project -> Run or click Run on the toolbar.
  4. The Emulator appears, running your MIDlet suite. The console displays system and trace output as a MIDlet suite executes.

For information on running a project locally versus remotely, see Chapter 2, "Developing and Running Applications.”

Debugging

You can debug an application from within the KToolbar by connecting to remote debugging facilities, such as an IDE debugger.

To debug an application under KToolbar:

  1. Choose Project -> Debug.
  2. The dialog asks you to enter a TCP/IP port number which the external debugger uses to connect to the emulator.

  3. Enter a TCP/IP port and click Debug.
  4. In most cases you can use the default value, but you should use another value if another application is using this port, or if you encounter problems connecting to the emulator from the debugger.

    The emulator begins running in debugging mode, and waits for a connection from a debugger.

  5. Start the remote debugger and attach it to the TCP/IP port you specified.
  6. Make sure to set the remote debugger to run in remote mode and to use TCP/IP. For more information, consult the debugger’s documentation.

Cleaning Up Project Files

To remove obsolete or unnecessary files in your project directory:

Packaging

You can create a package of your project files or create an obfuscated package that reduces the size of the Java bytecode, resulting in a smaller JAR file and possibly faster download times. Another benefit to creating an obfuscated package is to protect your code from possible decompilation.

To build a package:

A progress bar appears when packaging begins. When the packaging finishes, the output display indicates where the JAR and JAD files have been placed.

Output statements in main window after package creation.

FIGURE 8  –  Console Output After Packaging

Obtaining a ByteCode Obfuscator

The Wireless Toolkit does not provide a bytecode obfuscator. It does, however, contain a plug-in for the ProGuard bytecode obfuscator.

To get the ProGuard bytecode obfuscator JAR:

  1. Go to http://proguard.sourceforge.net/.
  2. Download the latest version of the proguard.zip file.
  3. Extract the proguard.jar file from the .ZIP file into the Wireless Toolkit’s bin directory: {j2mewtk.dir}\bin.
  4. If you choose to use a bytecode obfuscator other than ProGuard, you must implement the plug-in yourself. See the Wireless Toolkit Basic Customization Guide for an example of how to implement a bytecode obfuscator plug-in.


    Note – If your code uses the Class.forName() method to load classes, you may need to provide and use a script file as described in the following optional step.
  5. Save your script file under the project’s main directory and add the following key/value pair:
  6. 
    obfuscate.script.name: FileName  
    
    

    to the ktools.properties file located under WTK_HOME/wtklib/Windows directory. FileName is the name of your script file,

For more information about using script file formats, see the Proguard documentation.

Signing MIDlet Suites From KToolbar

After packaging the application, you can sign your MIDlet suite if needed by choosing the Sign command from the KToolbar’s Project menu. For information on signing MIDlet suites, see Chapter 6, "Using Security Features in the Wireless Toolkit.”

Running in OTA Provisioning Mode

When your MIDlets are packaged (and signed if needed), you can emulate OTA provisioning and run your application by choosing the Run via OTA command from the KToolbar’s Project menu. A graphical AMS is started and you can simulate the downloading and execution of your application from a web server. Running in OTA provisioning mode, enables you to test certain MIDP 2.0 features such as package validation, MIDlet suite authentication, and push functionality. For information on running using OTA provisioning in the Wireless Toolkit, see Chapter 2, "Developing and Running Applications.” For alternative ways of running in OTA provisioning mode, see Chapter 8, "Testing Application Provisioning.”

Using Class Libraries

KToolbar enables you to build projects from source and resource files. You may want to use a class library for which you do not have source files. This section shows you how to build a project using an external class library.

Be cautious when including external class libraries. Adding unnecessary class libraries to a project increases both the time needed to package it and the size of the resulting MIDlet suite JAR file. A large JAR file increases the time needed to load the MIDlet suite, and could prevent it from running on devices with low memory.

Class libraries for use with KToolbar should be compatible with the CLDC and MIDP APIs and should be packaged in .jar or .zip format. KToolbar provides ways for you to develop applications using class libraries, both on a per project and on a global basis.

External Libraries for a Specific Project

To add class libraries to a KToolbar project:

  1. Locate the directory containing your application (refer to TABLE 1).
  2. The application’s directory contains a subdirectory, lib.

  3. Place the JAR or ZIP file containing the class library into this subdirectory.
  4. For example, if you installed the J2ME Wireless Toolkit in C:\wtk21 and your application is called ExampleMIDlet, the class library would go in the directory, C:\wtk21\apps\ExampleMIDlet\lib. When you build, run, debug, and package your project, the class files in the lib directory are used.

External Libraries for All Projects

You can also define class libraries to be available for all projects that you develop with KToolbar. To do this, place the JAR or ZIP files containing the classes in the subdirectory apps\lib of the directory in which you installed the J2ME Wireless Toolkit. For example, if you installed the Wireless Toolkit in C:\wtk21, you would place the class libraries in C:\wtk21\apps\lib. Class libraries in the apps\lib directory are used for all projects.


Note – Class libraries for a particular project can import classes and resources from any general library as well as specific libraries. Class libraries for projects in general can only import classes and resources from general class libraries.

Using the Stub Connector to Access J2ME Web Services

You can generate a stub connector to access Web Services from the KToolbar. The Emulator is compliant with the J2ME Web Services Specification (JSR-172). The stubs are created using a Web Service Descriptor Language file.You can also generate a stub connector from the command line. See Appendix D, "Command Line Utilities.”

To generate a stub connector:

  1. Choose Project -> Stub Generator or select File ->Utilities -> Stub Generator.
  2. Enter or browse to the URL or location of the WSDL File and click OK.
  3. The Output Path is the location where the Stub Generator will place the generated files.

    The Output Path and the CLDC version default to the project settings if you generate a stub connector from the Project menu, as shown in FIGURE 9. Both options are from the KToolbar.

  4. Enter the Output Package Name.
  5. The Output Package name is the package name that the stub will be generated in.

    The screen displays the Stub Generator dialog box.

    FIGURE 9  –  Stub Generator Dialog

Setting Emulator Preferences and Using Emulator Utilities

You can access the Emulator’s Preferences and Utilities tools through the KToolbar menu.

To access the Emulator Preferences tool:

To access the Emulator Utilities tool:

For more information on using the Emulator Utilities and Preferences tools, see "Preferences and Utilities" in Chapter 5, "Working With the Emulator.”

Customizing KToolbar

KToolbar includes some advanced configuration options. You can use these options by editing the file {j2mewtk.dir}\wtklib\Windows\ktools.properties. To see the effects of your changes, restart KToolbar.

Setting the Application Directory

By default, the J2ME Wireless Toolkit stores MIDP applications in directories under {j2mewtk.dir}\apps. You can change this by adding a line to ktools.properties of the following form:


kvem.apps.dir: <application_directory> 

Any backslash ('\') characters in the directory’s path should be preceded by another backslash. Also, the directory’s path should not contain any spaces.

For example, to set the application directory to D:\dev\midlets, you would use:


kvem.apps.dir: D:\\dev\\midlets 

Setting the javac Encoding Property

By default, the Java compiler uses the encoding set in the J2SE environment that you are running. For information on how to override the default source file encoding, see "Java Compiler Encoding Setting" in Appendix C, "Internationalization.”

Working with Revision Control Systems

Using the filterRevisionControl property, you can configure KToolbar to recognize and ignore auxiliary files created by the SCCS, RCS and CVS revision control systems.

To recognize and ignore auxiliary files, include the following line in ktools.properties:


kvem.filterRevisionControl: true 

As a result, you prevent KToolbar from treating revision control files as source and resource files. For example, KToolbar would treat a file named src\SCCS\s.MyClass.java as being an SCCS revision control file and not a Java source file.

 


Contents Previous Next Index User's Guide
Java™ 2 Platform, Micro Edition, Wireless Toolkit, Version 2.1