Search:
|
Access:
» NetBeans IDE with NetBeans Mobility PackRelated categories: Java | IDE Martin Brehovsky, Karol HarezlakViewed: 8521 | Article date: 2006-05-11 15:17:04 In this article the authors would like to show how to create an application running on a mobile phone, which is able to connect to the server and get information from it. As an example the authors have chosen an application running on a mobile device with support for JavaME with MIDP profile (i.e. most of the mobile phones available today), which is able to monitor virtual machine of the JavaEE server using the Java Management Extensions API. They will use Java 1.5 and NetBeans IDE with NetBeans Mobility Pack installed – this is all we need to create and run the application.
In this article we would like to show how to create an application running on a mobile phone, which is able to connect to the server and get information from it. As an example we have chosen an application running on a mobile device with support for JavaME with MIDP profile (i.e. most of the mobile phones available today), which is able to monitor virtual machine of the JavaEE server using the Java Management Extensions API. We will use Java 1.5 and NetBeans IDE with NetBeans Mobility Pack installed - this is all we need to create and run the application. Martin Brehovsky is a software engineer in Sun's Software Systems Group, where he works on the NetBeans Mobility Pack as a project lead for the Visual Mobile Designer. Contact with the author: martin.brehovsky@sun.com Karol Harezlak is a software engineer in Sun's Software Systems Group, where he works on the NetBeans Mobility Pack project. Contact with the author: karol.harezlak@sun.com NetBeans IDE and Mobility PackBefore we start let us give you some information about the tools we are going to use to develop the applicatoin - the NetBeans IDE (if you are familiar with NetBeans IDE and Mobility Pack you can skip this section). NetBeans IDE is an open-source integrated development environment written entirely in Java. It is a single platform with out-of-the-box development capabilities and support for desktop (JavaSE) applications, enterprise (JavaEE) applications like web applications, EJBs and web services, and mobile/wireless (JavaME) applications (when NetBeans Mobility Pack is installed). The robust open source Java IDE, has everything that Java Software Developers need to develop cross-platform desktop, web and mobile applications straight out of the box.
Figure 1.NetBeans Mobility Pack 5.0 Beta2 NetBeans Mobility Pack, distributed as a free add-on for Netbeans IDE, can be used to write, test, and debug applications for the Java Micro Edition platform technology-enabled mobile devices. It offers many features and tools enabling development of application based on the Mobile Information Device Profile (MIDP) and the Connected Limited Device Configuration (CLDC). The tool is coming with integrated Sun Java Wireless Toolkit 2.2 (de-facto a reference implementation of CLDC/MIDP stack) and it allows easy integration of third-party emulators coming from device vendors like Nokia, SonyEricsson, Motorola and many others. One of the key features in the Mobility Pack is the Visual Mobile Designer. This tool enables rapid design and development of mobile applications (MIDlets) by letting users drag-and-drop components into Screen Designer, where the developer designs the individual UI screens and Flow Designer, where the developer specifies how the individual screens are connected together by defining the application flow. The designer automatically generates a compact Java code, which can be further enhanced manually in the source code editor. Mobility Pack also provides a solution for device fragmentation which helps developers deal with various implementation problems when targeting various devices with different capabilities. The developer can use integrated commenting preprocessor to specify parts of the code, which is used for different devices - thus can easily implement a workaround for a missing functionality or a bug on the particular device. Among other features there are two which allow easy creation of applications connecting to web servers and also web services from the mobile device. Using Mobile Client to Web Application and J2ME Web Service Client wizards, the IDE generates all necessary classes to allow developers easily use connect to servers from the mobile client. Creating the monitor applicationAs written in the introduction, we are going to develop an application, which is able to monitor various data from a virtual machine, which is used to run the web server. The monitor application consists from two parts - the first one is the server or back-end, which responsibility is to obtain the observed values from the virtual machine using the Java Management Extensions API and includes functionality, which enables the mobile client to connect to the server. For deployment we will use Tomcat web server bundled together with NetBeans, but any other JavaEE web server should work as well. The other part of the application is the client (front-end) - this is the actual application which runs on the mobile device. It contains UI, logic and the code which enables the mobile client to connect to the server. The client application will run on Sun Java Wireless Toolkit, which is a reference implementation for JavaME's CLDC/MIDP stack and is bundled with the NetBeans Mobility Pack. As with server, the client application should work on any other emulator/device, which implements at least CDLC 1.0 and MIDP 2.0. Client and server communicate via a binary protocol, which has been generally designed to easily allow JavaME applications to connect to the JavaEE web servers - the protocol is optimized for low-bandwidth and long-latency networks like GPRS.. The implementation of both sides of the protocol is being created by the IDE, using Mobile Client to Web Application wizard from NetBeans Mobility Pack. This wizard creates a several files with source code to both client and server projects. The protocol itself is basically a form of remote method call created specifically for the actual set of methods being exposed - it contains an identifier of a method to call together with its serialized parameters and returns back serialized return value. As first we will create the server part - more specifically the code which is using the Java Management Extensions to get the runtime information about the virtual machine. Then we will create the mobile application - we begin with creating the UI using Visual Mobile Designer and then we will continue with using the Mobile Client to Web Application wizard to create the code for connecting the client to the server. After that we will bind the created code with the UI, deploy the server part on the server and run the client. Part 1 - creating the monitor application back-endThe first thing we need to do is to create a web project, which will work as a back-end for our application. To do so, we make sure NetBeans IDE is started and bring up a New Project wizard by clicking on File->New Project menu. Here choose Web category and Web Application project and click on Next button to advance to the second panel of the wizard. In this panel set the name of the project to MonitorServer and possibly choose a location for your project (Project Location), other settings should stay in default values. When done click on Finish button to create the project. When the project is created, you should see it in the Projects view and in the editor there should be opened index.jsp file. You can close it, because we will not write any JSPs for this project. Now let's create the class accessing and getting the information from the JMX. To do so, use a pop-menu on the created project in the Projects view and choose New->Java Class. In the dialog which has just appeared, type name of the class you would like to create (e.g. Monitor) and a package in which the class should be located (e.g. monitor). Click on Finish button to create the class and the source file for the class should open in the editor. Implement the functionality of the monitor as seen in the listing 1. When done with typing, you can check the project can be compiled using Build Project item from project's pop-up menu. Listing 1. The class monitoring virtual Java machine using JMX
package monitor;
|
|
Copyright C 2006 by Software Developer's Journal. All rights reserved.






SDJ Users:
Shopping Cart









