Setting Up Environment

Published on January 2017 | Categories: Documents | Downloads: 44 | Comments: 0 | Views: 202
of 4
Download PDF   Embed   Report

Comments

Content

Setting up Your Mobile Programming Environment for J2ME

Task 1: Setting up your environment You should set up your own environment for assignment work, the following are the basic steps you will need to do set up your “development environment”. For developing your assignment, you should use NetBeans as the development environment (you can use the Sun Wireless toolkit directly or you can use Eclipse). You should use NetBeans 6.5 (or at least one newer than 5.5.1), as an older version may not be configured for J2ME development. Suggestion: you may wish to try this under Windows as opposed to Linux, since that seems to be the most stable; but feel free to try Linux (let me know if it works and we can pass this on to the class!):  To begin with, you will need a copy of the JDK (6.11 is latest), which can be downloaded (see “Useful Links” on course web site). Install it, if you don’t have it. You will need a wireless toolkit that provides an emulator, tools, documentation, sample code, and other useful items for your development. More often than not, toolkits should be installed before other development tools, but will likely need to have the JDK installed first. It is recommended that you use Sun's Wireless Toolkit (2.5.2 or 2.5.1 for CDLC should be fine). It is stable, full featured, and comes with lots of documentation. Install it. With a wireless toolkit installed, you now need to select a Java IDE to use. (Sun's toolkit, however, can be used on its own, if you'd rather go that route.). As indicated, using NetBeans; make sure you choose a version that supports Java ME (there are two choices, but one gets you almost everything!). Install it. You can also use Eclipse as your IDE, along with EclipseME to interface with the mobility side; we have not tried it for a while, but earlier versions seemed less stable than NetBeans. You are welcome to try Eclipse if you wish. If you are feeling particularly adventurous, you can try to set up your development environment under Linux. In theory, this is possible; but I haven’t









tried for a while and not with newer versions of NetBeans and JDK. If you go this route, document what you do if you succeed! For further information, please consult the documentation for the various software packages in question. Task 2: Testing your environment Now that you have access to a development environment (hopefully, everything went well during the installs!), you need to get the project set up. To do so, follow these steps, assuming you are using a NetBeans environment. If you are doing something different, you will have to modify these steps accordingly for the environment in question.  First you need to download the sample code package from the source code link on this website. Look under the section titled “Book Extras” – there should be a link titled “Source Code”. This should take you to a page where you can download a .zip file containing all of the source code from the Beginning J2ME text book. Of interest to us for this assignment is the CameraMIDlet code from Chapter 16 of the book, naturally found under the ch16 directory of the source tree. To create the project in NetBeans, select the New Project option from the File menu. In the window that appears, select Java ME from Categories, and then select the Mobile Project from Existing MIDP Sources option under Projects. You can now click Next to move on to the next step. Now, NetBeans wants you to specify sources. There are no JAD files (Java Application Descriptor (JAD) files describe the MIDlets (Java ME applications) that are distributed as JAR files. en.wikipedia.org/wiki/JAD_(file_format) ) or Manifest files (see below) at this point for this project, so you only need to specify the source code location. To do this, click the Browse option in the window that appears, and find the CameraMIDlet directory under ch16 in the source tree. Do not dig deeper ... just select the CameraMIDlet and click Open. You can click Next again now to move on. [Aside: A JAR file is a file format based on the popular ZIP file format and is used for aggregating many files into one. A JAR file is essentially a zip file that contains an optional META-INF directory. A JAR file can be created by the command-line jar tool, or by using the java.util.jar API in the Java platform. There is no restriction on the name of a JAR file, it can be any legal file name on a particular platform. In many cases, JAR files are not just simple archives of java classes files and/or resources. They are used as building blocks for applications and extensions. The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension and services. The files in the META-INF directory are recognized and interpreted by the Java 2 Platform to configure applications, extensions, class





loaders and services. The manifest file (MANIFEST.MF) is used to define extension and package related data.]   You have now set the name and location of the project. For your installation of your own, these should be fine by default. You now get to select the platform. You should use the Sun Java Wireless Toolkit 2.5.2 (or 2.5.1) for CLDC option. You should select the DefaultColorPhone as the device; you do have the option of changing the device, but the DefaultColorPhone is quite suitable. A device configuration of CLDC-1.1 is fine, but you should change the device profile to be MIDP-2.1. You can now click Finish to create the project. The code we will be working with can be found in the CameraMIDlet.java file of the project. Before building though, we need to double check a couple elements of the project properties. The easiest way to do so is to right click on the project name (ImportedProject-CameraMIDlet by default if you didn't change it in importing things). This should be findable in the projects tab on the left side of the screen. From the menu that pops up, select Properties. Select the MIDlets entry under the Application Descriptor category on the left side of the properties window that appears. It should say that there is a CameraMIDlet in the suite. This is the correct name, and you should be fine. If this is empty, or the name or class are not CameraMIDlet1; it should pick the right name automatically. It's basically the name of the MIDlet class defined in the .java file. Now select the Libraries & Resources entry under the Build category now. The Bundled Libraries and Resources area on the right is likely empty. We need to add a folder there, the one containing project resources. (Currently just a question mark image.) To do this, select the Add Folder button. Go all the way back through the book source code as you did before, and again find CameraMIDlet folder. This time, enter this directory and select the res directory under there and click Open and then Ok. This tells the build system to include all resources from this directory in the .jar file it creates. Please note though that if you add resources to this directory, that you need to do a clean build to have it find the new resources. Now we're ready to build and test this out. From the Build menu, select the Clean and Build Main Project option. It's likely best to do this the first time you build ... later on, you can typically just use the Build Main Project option instead, unless you really want to clean things up, to save time. This should build without problems. Now it can be run. To do so, you select the Run Main Project option from the Run menu. (Of course there are short cut keys and buttons you can use to accelerate the process, if you so choose.) This will launch the emulator, which looks pretty much like a cell phone. Your program











can be run by using the soft keys under the window; the emulator is pretty intuitive as it functions pretty much as a cell phone would. Is you are unsure about how to use it, consult the documentation that is installed along with the Sun Wireless Toolkit.  You can run your MIDlet using the Launch option in the emulator. (This shouldn't be the problem as it's the only command bound to a soft key in your emulator when it first starts anyways.) Once you launch your MIDlet, you are good to go to test it out! When done you can terminate the emulator by closing the window, or using the power off switch on the virtual phone, which is on the top-right corner of the phone. Note that by default, you will need to authorize your MIDlet to do various things, including accessing the camera or the network, for security reasons. That's normal, so don't worry about it!

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close