Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Sunday, August 23, 2009

Setting up the tools for J2ME app development

Aim: To setup tools and environment for J2ME application development
My OS: Ubuntu jaunty

JRE

1. Download and install JRE (Java Runtime Environment) using the Synaptic Package Manager. The JRE is required for Eclipse to run.

Eclipse

2. Download and install Eclipse. I use this Eclipse Ganymede package.
Make sure you are able to launch Eclipse after it has been downloaded and extracted.
If Eclipse won't start with messages like 'Widget disposed too early', try adding this line to eclipse.ini
-Dorg.eclipse.swt.browser.XULRunnerPath=/usr/lib/xulrunner
this worked for me! BTW, eclipse log is located at /.metadata/.log
.metadata is a hidden folder!

Sun WTK

3. Download and install the Wireless Tool Kit. Although, Sun now has a Java ME SDK 3.0, it is currently available only for Windows. I use the earlier Sun Java Wireless Toolkit 2.5.2. Extract the contents to a suitable directory.

EclipseME plugin
4. Next we proceed to download the plugin to help us develop the J2ME midlets. Although the EclipseME project has graduated and is now called Eclipse Mobile Tools for Java (MTJ), I did face some problems with it on my Ubuntu machine. Problems were especially related to Proguard not being able to find my inner classes and throwing NoClassDefFound errors during Obfuscation. Hence I decided to switch back to the tried and tested EclipseME 1.7.9 plugin.
To install, use Eclipse's Software Updates feature and add the site http://www.eclipseme.org/updates


Proceed with the installation. Restart Eclipse if asked to. After successful installation, you should be able to see a new 'J2ME' option under Eclipse -> Window -> Preferences

Proguard
5. This is a must if you wish to optimize the resulting jar and also make sure nobody copies your code (Obfuscate). I downloaded the latest Proguard4.4.tar.gz version. Extract it to a suitable directory.

Antenna Eclipse Plugin

6. Add the plugin update site http://antenna.sf.net/update via Eclipse's Software Updates feature and install it.


Proceed to install the plugin. Restart Eclipse if asked to.
Installation guide is here.

You can also download the Antenna Jar
This is required if you wish to build using Ant (build.xml) How to set it up and use it will be covered in another post.

Wiring it all!

Browse to Eclipse -> Window -> Preferences -> J2ME (Left side option)
Set the Antenna JAR and WTK Root properties
Antenna JAR (antenna.preprocessor.v2_1.7.7.jar) will be located under Eclipse/plugins directory
WTK Root is where you extracted the contents in Step 3 above.


Import the Sun WTK Emulation devices in Eclipse

Open Eclipse -> Window -> Preferences -> J2ME (Left side option) -> Device Management
Click Import
In the Import Devices dialog that pops up, browse for the WTK/bin directory.
Click Refresh. You should see this.

Click Finish

On Preferences screen, Click J2ME -> Packaging -> Obfuscation and set the Proguard Root Directory.
Set it to the path where you extracted Proguard contents in step 5 above. Mine is /media/sda5/Dev/proguard4.4

All Done!

Now import an existing project or create a dummy project.
Right click on the project and enable 'Antenna Preprocessor'.
Now if you see the Project Properties (Alt-Enter), you should see a new option 'Antenna preprocessor' under it.



JMUnit
If you wish to write Test cases, you should consider adding JMUnit jar to your project classpath.

A nice guide on using JMUnit is here

You are all set to start J2ME programming.
Next, I ll post on how to actually start using these tools and make the most out of it.

Saturday, August 15, 2009

J2ME programming tools

In my experience, these are the tools required for developing mobile applications (midlets).

Eclipse IDE. The latest is Eclipse Galileo. I use Eclipse Ganymede.
Mobile Java Tools plugin for Eclipse.
Sun Java Wireless Toolkit The latest is Java ME SDK 3.0, but I use WTK 2.5.2 separately
Antenna Preprocessor

In another post, I ll be talking about how to use these tools to develop and application.

Update - MJT experience :(
Recent experience with Mobile Java Tools was not good. I faced problems with unnecessary NoClassDefFound errors on inner classes, probably something to do with the preverifier and obfuscator (proguard). So I decided to switch back to the tried and tested EclipseME 1.7.9 Plugin

Update - More tools:
Proguard (latest is v4.4) - Obfuscator, preverifier etc to safeguard and optimize the code
JMUnit - for unit testing (my research tells me that JMUnit is better than j2meunit, also at sourceforge)

Thursday, July 9, 2009

Configure Eclipse and MySQL on Ubuntu Jaunty

I assume that Eclipse and MySQL has already been installed. I use Eclipse Ganymede (3.4.2) and MySQL 3.5.1. For installing MySQL on Ubuntu, see my previous post.

1. Download MySQL JDBC Connector (mysql-connector-java-5.1.7.zip/jar)

Choose a mirror and download from here

Extract the contents of the jar/zip to a folder.

2. In Eclipse, click Menu -> Window -> Show View -> Other. Expand the 'Data Management' option and select 'Data Source Explorer'.

Click OK. The Data Source Explorer tab will open.

3. In Data Source Explorer, right click 'Database Connections' folder and click New.

The 'New Connection Profile' dialog will open. Select 'MySQL' and click Next.

Most likely your Drivers drop down will be empty. If yes, then it is time to create a new Driver definition.

4. Click on the small 'New Driver Definition' icon next to the drop down.

5. In the dialog that opens, select MySQL JDBC Driver v5.1. 

6. Click Jar/List tab. You need to add the MySQL JDBC connector jar that you downloaded and extracted in step 1 above. Click Add JAR/Zip and select the mysql-connector-java-5.1.7.jar that you extracted. Click OK

7. Change the Database from 'database' to 'mysql' in both Database and URL fields.

8. Enter the password that you had provided during MySQL installation.

9. Click Test Connection and you should see a ping succeeded dialog.

10. Click Finish. Your database connection is successfully created. If you Expand the connection tree, you can see the database and tables etc.

Happy querying!

Install and setup MySQL on Ubuntu Jaunty

Here is how I installed MySQL 5.1 Community Edition on Ubuntu Jaunty:

1. Install MySQL

Goto Synaptic Package Manager and in quick search type 'mysql-server-5.1' (without quotes). From the list that will be provided, choose to install package with name mysql-server-5.1. It will show you all the dependencies and proceed to install.

Alternately you can use apt-get command.

sudo apt-get install mysql-server-5.1

1a. During the installation it will prompt for a password. Enter password of your choice.

1b. Confirm the password. Make sure installation completes successfully

2. Test the installation

To test the installation, type the following in Terminal.

mysql --user=root --password=yourpassword

"Welcome to the MySQL monitor. Commands end with ; or \ g.
Your MySQL connection id is 53
Server version: 5.1.31-1ubuntu2 (Ubuntu)

Type 'help;' or '\ h' for help. Type '\ c' to clear the buffer."

After this you should be able to see the prompt change to

mysql>

3. Use the mysql database.

mysql> use mysql;

"Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed"

4. Now see the tables present in the database

mysql> show tables;

This will display all the tables present in the database.

MySQL has been successfully installed.

In the next post I ll show how I configured Eclipse to talk to MySQL!