Preparing Eclipse
In this section, you will verify that Eclipse is properly set up
for Java ME development.
The following is assumed:
- You are starting with a new Eclipse installation with default
settings.
- You are familiar with the basic Eclipse workbench mechanisms,
such as views and perspectives.
If you're not familiar with the basic workbench mechanisms,
please see the Getting Started chapter of the Workbench User Guide.
Java ME SDK installation
In order to use MTJ, you must configure at least one device from
a Java ME SDK, performing the following steps:
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workbench)")"> Window > Preferences... to open the workbench preferences.
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.mtj.ui.preferences.deviceManagementPreferencePage)")"> Java ME > Device Management preference page to display the installed SDKs.
-
New devices can be added by searching the hard drive for
installed Java ME SDKs. To do so, simply click the Import...
button.
-
In the resulting dialog, select the root directory to be
searched to find known devices definitions.
As you leave the search directory text field or select the Refresh
button, MTJ will begin looking for devices in the specified directory
and all subdirectories.
It is not necessary to pick the "perfect" directory in order to
have the devices from a SDK imported, as MTJ should be able to locate
them if they reside anywhere within the specified directory.
The devices from the SDKs will be displayed as they are being
found, and if you wish to stop the search at any time, select the Cancel
button.
After the search has completed, use the checkboxes to select the
device definitions to be imported. Only devices that have been imported
into your configuration may be used by project definitions and for
launching.
Finally, click the Finish button to complete
the import process.
-
If you successfully completed adding at least one device from
the Java ME SDK, you should see the newly installed SDK in the Installed
SDKs combobox and its imported devices in the Devices table as seen
below.
Debug Settings
In order to debug your Java ME MIDlet, you must change some of
the default Java debug settings, performing the following steps:
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workbench)")"> Window > Preferences... to open the workbench preferences.
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.jdt.debug.ui.JavaDebugPreferencePage)")"> Java > Debug to open the debugging preferences.
-
Ensure that both Suspend execution on uncaught
exceptions and Suspend execution on compilation errors
near the top of the dialog are NOT checked.
-
Increase the Debugger timeout near the bottom
of the dialog to at least 15000 ms.
-
The resulting settings should be something similar to this:
-
To save the preferences, simply click on the OK
button
Configuring Preprocessor Support
Due to limitations in the extensibility of the Eclipse Java
Compiler (see Bug 116143 for further information), it is necessary
for MTJ to hook into the Eclipse platform at a lower level in order to
provide preprocessor support. If you would like to take advantage of
MTJ's support for preprocessing, a few extra changes need to be made to
your Eclipse installation.
The Eclipse configuration file must be altered to reference the
MTJ framework hooks bundle.
- Locate the file config.ini. This file is located in the <eclipse install>/configuration
directory.
- Edit the config.ini with your favorite text editor.
- Add the property definition bellow to the configuration file.
osgi.framework.extensions=org.eclipse.mtj.core.hooks
If the property already exists, append ",org.eclipse.mtj.core.hooks"
to the end of the current property definition.
It is very important that the line be added before the end-of-file
marker. Failure to properly place the new line before the end-of-file
marker could cause your Eclipse workbench to fail to start.
- Save the configuration file.
- You will need to restart your Eclipse installation.
You will be warned if you have projects that are configured for
preprocessing, but the necessary configuration changes have not been
made. In this case, a warning will be written to the Eclipse workspace
log file with text similar to
"Preprocessor invoked, but hook is not installed. Consult the
installation instructions for MTJ."
For more information on viewing the workspace log file see the troubleshooting
section of the MTJ documentation.
Configure ProGuard
In order to use ProGuard to produce obfuscated packages, you will
need to configure it into MTJ, performing the following steps:/p>
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workbench)")"> Window > Preferences... to open the workbench preferences.
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.mtj.ui.preferences.ObfuscationPreferencePage)")"> Java ME > Packaging > Obfuscation preference page to display the Obfuscation
preferences.
-
Configure the ProGuard Root Directory near the top of the
dialog.
-
Configure any other ProGuard-specific settings that you need.
Important note for Microsoft Windows Users: By default,
ProGuard assumes that you are using an operating system that can
distinguish between two file names that differ only in their case (i.e.
A.java and a.java
are two different files. This is clearly not the case in Microsoft
Windows. Windows users should be sure to specify the -dontusemixedcaseclassnames
option to ProGuard. If you fail to do this, and if you have more than
26 classes in your project, ProGuard's default use of case-sensitive
file names will cause classes to overwrite one another. For safety, the
-dontusemixedcaseclassnames option is included as one of the
default arguments to ProGuard. UNIX users with projects with many
classes may be able to achieve a small reduction in the final size of
their JAR file by removing this option.
-
To save the preferences, simply click on the OK
button
Configure Over The Air options
In order to debug your MIDlet in Over The Air (OTA) mode, you may
want to adjust the OTA Preferences, performing the following steps:
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Workbench)")"> Window > Preferences... to open the workbench preferences.
-
href="eclipse_java_me_javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.mtj.ui.preferences.J2MEOTAPreferencePage)")"> Java ME > Over the Air preference page to display the Over the Air preferences.
- Configure Over The Air options
-
To save the preferences, simply click on the OK
button