Sun WTK of J2ME development environment

Source: Internet
Author: User
Tags contains copy execution include requires resource versions web services
What is J2ME Wireless Toolkit

WTK's full name is the wireless development kit for the Sun J2ME Wireless Toolkit--sun, which can be developed in the Java Technology for the Wireless Industry (Jtwi, JSR 185) A Java application running on a fan-compatible device. The toolbox contains build tools, utilities, and device emulators. By the time this article was written, there were four versions, namely 1.0.4, 2.0, 2.1 and 2.2. Each version includes English, Japanese, Simplified Chinese, Traditional Chinese 4 language packs.

The 1.0.4 version can only develop MIDP1.0 applications.

Version 2.0 can only develop MIDP2.0 applications.

Version 2.1 can be developed at the same time MIDP1.0, Jtwi (CLDC 1.0, MIDP2.0, WMA1.1, can instead CLDC1.1 or join MMAPI1.1), custom (own random combination configuration, Profile and optional Package) three different environments.

In version 2.2, WTK supports MIDP 2.0, CLDC 1.1, WMA 2.0, Mmapi 1.1, Web Services (JSR 172), File and PIM APIs (JSR), Bluetooth and OBEX APIs (JSR), and 3D Graphics (JSR 184), and you can also use this edition to develop applications for CLDC1.0 and MIDP1.0.




System requirements, WTK2.2 requires at least 50MB of available hard drives, 128MB system RAM and 800MHZ Pentium III CPUs.




You can download it at Sun's official website for free.

WTK2.2 download link (need to log in first):

http://sdlcweb3b.sun.com/ECom/EComActionServlet;jsessionid=FE979CDFE94DE539C8DE6CF74FED7878










Section II J2ME the content and file structure of WTK

Before we explain the WTK file structure, let's install it first.

The WTK installer is as simple as a normal program, with only one point to note that since WTK does not have a Java-run environment JDK, you need to install your own JDK before WTK installation (the author chooses JDK1.4.2 here).

WTK first detects the current system's existing Java virtual machines:



Then show the path of the current virtual machine



Once you are sure, you can continue, and after the installation is successful, you will get a development package that includes a variety of utilities.






Whichever version of WTK will include the following directories:

APPDB Directory: RMS Database information

Apps Directory: WTK demo program with its own

Bin directory: J2ME development tool Execution file

Docs directory: various Help and documentation

LIB directory: J2ME library, Jar Pack and control file

Session Directory: Performance monitoring save information

Wtklib Directory: JWTK main program and emulator appearance




WTK is used to develop MIDP, and in order for MIDlet to compile and execute smoothly, WTK must have CLDC and MIDP class libraries, WTK can help us save time for additional installation and debugging of these class libraries. Different versions of WTK contain library content that is not the same, for example, 2.0 contains Midpapi.jar, Wma.jar, Mmapi.jar, and in 2.1 it becomes cldcapi10. Jars, Cldcapi11.jar, Midpapi10.jar, Midpapi20.jar, Wma.jar and Mmapi.jar; in 2.2, Wma.jar is subdivided into Wma11.jar and Wma20.jar. If you need a particular jar package in development and the current version of WTK is not available, you can simply copy the jar package like the current WTK Lib folder.




The apps directory includes a number of demo programs that show us some of the technical examples of J2ME, which are often good learning materials.










Section III using J2ME WTK to create a project

Create a new project

Let's use WTK to create a classic Hello World program to see how deep the water is.

Run Ktoolbar in the WTK list of programs and open the WTK main interface. WTK's title menu provides a straightforward list of optional features for this toolkit.

Click the new project, type the new project name and start MIDlet name, where the item is a MIDlet suite, typically with the same name as the MIDlet file (Java file).






After the project is generated, a setup table for the project appears, where you can select the current target platform, the CLDC configuration, and the MIDP optional package to be used. When you do not need a library file, do not select it to reduce the final program size.

Alternatively, you can specify the properties of the MIDlet, which will become jad, the description document for the J2ME program.

Our Hello world does not need other additional settings at the moment, so take the default and confirm that the console information prompts you to establish success.








After the project is WTK, different types of resources have a relatively fixed place of storage. Java source files are placed under the Apps directory under the \hello WORLD\SRC, the relevant program resource files (Pictures, audio) placed under the \hello World\res, the application library files in \hello World\lib, which must be noted in the WTK, Even relative paths must be established in that type of directory.




Once the project has been created, we will create a MIDlet file, MIDlet is the entry file for the J2ME project file, and it is also necessary. Create the Helloworld.java in the \hello world\src directory with the default package, note that the Java program you create must be the same as the MIDlet class name we typed when we created the project.




Enter the code in the newly created Java file, which is a simple welcome form program.

Import javax.microedition.lcdui.*;

Import Javax.microedition.midlet.MIDlet;




public class HelloWorld extends MIDlet {




Display display;


Public HelloWorld () {

Super ();

display = Display.getdisplay (this);

}




protected void startApp () {

Form form = new Form ("Hello world!");

Form.append ("Welcome to J2ME world!");

Display.setcurrent (form);

}




protected void Pauseapp () {




}




protected void Destroyapp (Boolean arg0) {


}

}




When you're done, save the Java file, click the WTK build key, and compile it for you by WTK, prompting you in the console if you have an error generation.






Modify the MIDlet file according to the hint information, and then rebuild until the compilation succeeds. To compile a successful program, perform a run, you can see a pop-up phone simulator, showing our first Hello World program, if the execution is wrong, still will give a message in the console.






Open Old Project

When we restart WTK next time, we choose to open the project, WTK will display all the applications under the Apps directory, including the Hello World we have just created, we can rerun it after we choose to load it.












Section Fourth performing MIDlet, packaging and obfuscation

Execute MIDlet

In addition to the one we just introduced to execute a program in Ktoolbar, we can also select the run MIDP application directly in the program group ..., which is where you can select the Jad program in the other path in the pop-up dialog box to run.











When we choose to run directly, we need to pay attention to two questions:

1. The jad description file is in the same directory as the jar file specified by it.

2. Do not include Chinese in the Run directory path.

Packaged into Jars

Ktoolbar's build capability will only help us compile and audit the source code, and will not help us produce jar files, and if we want to release the MIDP program, the jar is necessary in addition to the Jad description file, which requires packaging.

The Ktoolbar selected item--Package--produces a package that packages the entire program, including the resource file, into a jar file. The resulting jar is saved in the Apps\helloworld\bin directory.









Packet obfuscation

In the above operation, we see that in addition to the "Generate package", there is also a "Generate confusion package" option. The so-called confusion, is to prevent others to read the source code after the compiler, the program (. class file) to confuse, after the confusion of Java Byte code can increase the time to decompile, even if the decompile, the class name will change into meaningless symbols and increase the difficulty of understanding the source program. Further, due to confusion greatly shortened in the source program class, member variables and method names, resulting in a smaller jar size!

At present, the commonly used obfuscation is two open source products: Proguard and Retroguard, this article uses the former as an example, you can get on the http://proguard.sourceforge.net/.

Extract the Proguard just obtained, find the Proguard.jar file in the Lib subdirectory of the unpacked directory, copy it to the bin of the WTK installation directory, and then execute the obfuscation package. This is where we will find that the jar size under Apps\helloworld\bin is smaller, and the various names that have been recompiled have become meaningless.









The fifth section WTK other features that deserve attention

Here we have a more detailed description of how to create, execute, package, and confuse a MIDP project with WTK. In addition to the above points, WTK (version 2.2) also offers many practical features. These can be found in the editorial-preference.



For example, when we need to monitor the performance of the program, we can select "Enable Memory Monitor", the next time the simulator executes, we can read the program runtime memory consumption mean, peak consumption and the number of specific objects and usage.








In addition to memory monitoring, we can perform network monitoring, set the storage size and stack size, set the security signature and Bluetooth operation properties to simulate the actual operating environment of the mobile phone as much as possible, these features are very useful in advanced development.




Attention:

Although WTK provides us with a variety of tools to simulate the mobile operating environment, but in actual development, due to the mobile phone hardware, network conditions and many other restrictions, MIDP authenticity can be different machines on different responses, and the performance of WTK may be more difference.






Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.