J2ME and Web Services:Part 2 – Configuring Apache Tomcat


In the previous tutorial, I went over what web services are and the benefits they offer. In this tutorial we are going to set up the neccesary environment so that we can get started.

For this to work you need to have the following ready;

  1. A JDK installed in your machine
  2. You have downloaded Eclipse Galileo and extracted it – if you haven’t please refer to the previous tutorial.

I am assuming that you now have a copy of Jakarta Tomcat version 5.0 or any other version above this as they all work the same. If you dont have it you can get a copy by following this link . Extract the zipped file you downloaded to any location on your computer. With Jakarta,that is all as we don’t need to do any installation.

This tutorial is going to cover how to configure Tomcat and fire it up from Eclipse.

Setting up the Enviromental Variables

We know need to configure the following;

  • CATALINA_HOME – This is the path to Tomcat folder you extracted
  • JAVA_HOME – This is the path to your JDK
  • CLASSPATH – This is the path to the JDK lib folder and Tomcat lib folder

My configurations are on Windows 7 but it is not much different on other versions of Windows. To set up these variables we are going to follow the following steps;

  1. On “Computer” icon right click and select “Properties” and then choose “Advanced System Settings
  2. You then proceed to the “Environmental Variables
  3. You now have to create a new system variable by selecting “New“as shown by the screen shot below
  4. adding a new system variable

    adding a new system variable

  5. The above action will result in the following screen being shown
  6. New System variable

    New System variable input screen

  7. From here we can now add the paths we need. Note that this dependent on yourconfigurations. My variables are as follows;
    • JAVA_HOME – C:\Program Files\Java\jdk1.7.0
    • CATALINA_HOME – D:\tomcat (Note: I extracted Jakarta Tomcat to a folder in D and renamed it as jsut “Tomcat”)
    • JAVA_HOME – C:\Program Files\Java\jdk1.7.0\lib,D:\tomcat\common\lib

Adding Apache Tomcat to Eclipse

Now that we have the above configured we can now test that Tomcat is working.Start your Eclipse and choose your workspace. We need to add Tomcat to Eclipse so that we can run it from Eclipse as opposed to starting it separetely. This is done as follows;

  1. In Eclipse go to “Window>Preferences” and then select the “Server” tab as shown in the screenshot below
  2. Eclipse preferences

    Eclipse preferences settings

  3. To add a new server instance select “Runtime Environments” and you will get a screen like the one shown in the screenshot below
  4. Server Runtime Environment

    Server Runtime Environment

  5. Click on the “Add” tab and then select the version of Tomcat you want to install as shown by the screenshot below
  6. Tomcat Version selection

    Tomcat Version selection

  7. Choose the version of Tomcat you have,for this tutorial I am using Tomcat 5.0.28 and so I chose v5.0 and then press next and you will get the screenshot below
  8. Browse to tomcat folder

    Browse to tomcat folder

  9. You then browse to the folder where you extracted Tomcat. However there is one more thing we need to do;we are not going to use the default JRE but rather the installed JDK so please click on the “Installed JREs” to add the JDK. You will get a screen like the one shown in the following screen shot
  10. Adding JDK as an Execution environment in Eclipse

    Adding JDK as an Execution environment in Eclipse

  11. Click on “Add” and you will get a screen similar to the one shown in the screenshot below
  12. Choosing the type of JRE to  install

    Choosing the type of JRE to install

  13. Select “Standard VM” and then click on the “Next” button and you will be presented with a screen where you will specify the path to your JDK. The result of the selection should be as shown below;
  14. Installation of JDK as an enviroment in Eclipse

    Installation of JDK as an enviroment in Eclipse

  15. From there you just have to select the JDK as your JRE for Tomcat and follow the wizard until you are done. I skipped this part because it is fairly simple,if you face any problem,kindly let me know.

Testing Tomcat in Eclipse

To complete this second part of the tutorial we are just going to test whether the server is running. At the bottom of the Eclipse window is the pane that usually displays the console output. There is a tab for Servers,select the tab and you will see a screen similar to the screenshot below;

Starting Apache Tomcat in Eclipse

Starting Apache Tomcat in Eclipse

 

Click the start button to start the server and make sure you allow it to access both private and public networks.

That will be all for today,in the next tutorial we are going to create a simple J2ME application that allows a user to login into a system with the user details stored in a database.

Advertisements

2 thoughts on “J2ME and Web Services:Part 2 – Configuring Apache Tomcat

  1. Pingback: Using Java web services to connect J2ME app to the internet: Part 1 « KiruinC

  2. Pingback: Creating a simple J2ME app: Part 3 of Java web services « KiruinC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s