Developing, Debugging and Deploying Java Web Services with MySQL on Apache Tomcat and Axis on Windows


This document will help you get up and running developing web services in Java using various tools. It's not really as hard as it seems. OK it can be, but only if you don't follow my advice. Despite what they tell you, you can do all of this on Windows (I used XP, I have no reason to suggest none of this wouldn't work on 2000). Note that a bunch of the paths for things are not necessarily the best place to put things, but represent what I could get to work. :-P

Get Set Up

Install the following software:

A Java 2 SDK, e.g. J2SE 1.4.2
Look for a Windows Installer and run it.
MySQL (4.0)
Look for a Windows Installer and run it. You may have to run the winmysqladmin.exe utility in c:\mysql\bin first before you can connect to the server using phpMyAdmin
Apache HTTP Server (2.0)
Look for a Windows Installer and run it.
PHP (4.3.8)
Look for a Windows Installer and run it. I tried 5.0 and it didn't work, so use the 4.3.8 installer.
PHP MyAdmin
Follow the installation documentation and installation is easy.
Apache Tomcat (5.0)
Look for a Windows Installer and run it. I would install Tomcat into the same parent folder as the HTTPD for convenience - but it's up to you. I put it in C:\Program Files\Apache Group\Tomcat 5.0 - we'll call this %CATALINA_HOME%. Important - for some reason when you run the Tomcat SERVICE it uses its own crackbaby %CLASSPATH% instead of the one you set, so don't do that - run tomcat by running %CATALINA_HOME%\bin\startup.bat
Apache Axis (1.1)
Download the .zip bundle and extract the files somewhere near Tomcat, I placed all this in C:\Program Files\Apache Group\axis-1_1. We'll call this location %AXIS_HOME%. Copy everything in %AXIS_HOME%\webapps\axis into %CATALINA_HOME%\webapps\axis.
Connector/J (3.0)
Download the .zip bundle and place mysql-connector-java-[version]-bin.jar it in %CATALINA_HOME%\webapps\axis\WEB-INF\lib\ (this is just where I put it, and probably not a very good location but this is where I could get it to work; I also renamed the jar file mysql-connector.jar for easier reading) - if you put it elsewhere, you'll need to adjust the AXISCLASSPATH value below.

Environment Variables

Getting your environment set up is crucial for things to work. You will save yourself hours of pain if you check this carefully now. Note that you should not put trailing slashes on environment variables that are paths to directories.
AXIS_HOME This is where you put Axis, e.g. C:\Program Files\Apache Group\axis-1_1
AXIS_LIB Axis' lib dir, set to %AXIS_HOME%\lib
AXISCLASSPATH %AXIS_LIB%\axis.jar;%AXIS_LIB%\commons-discovery.jar; %AXIS_LIB%\commons-logging.jar;%AXIS_LIB%\jaxrpc.jar; %AXIS_LIB%\saaj.jar;%AXIS_LIB%\log4j-1.2.8.jar; %AXIS_LIB%\wsdl4j.jar; %CATALINA_HOME%\webapps\axis\WEB-INF\lib\mysql-connector.jar
CATALINA_HOME Where Tomcat Lives, e.g C:\Program Files\Apache Group\Tomcat 5.0
JAVA_HOME Where your Java 2 SDK lives - e.g. C:\Program Files\j2sdk1.4.2_04

Developing Web Services

This script will automate most things, providing your environment is set up properly (see above). Place it in the same folder as your source files. It assumes you have a structure matching the package name over in %AXIS_HOME%, e.g. %AXIS_HOME%\org\mozilla\update\extensions for package org.mozilla.update.extensions. Invoke the script from a unix shell (use cygwin) like so: ./ WebServiceClassName - e.g. ./ VersionCheck org.mozilla.update.extensions

I hope to come up with something better here but in the mean time read Getting Started using Web Services with Tomcat and AXIS - it has a Unix slant but pretty much everything applies.

A note when returning complex types - say you want to return a complex data type (equivalent to a C struct or C++ class) - you can't just use a Java class with a bunch of public fields on it since the Axis WSDL2Java generator transforms public fields into private ones and replaces them with accessor methods - which will cause your code not to compile if you're not careful. The solution is to define accessors on your complex data type yourself.

Debugging your Service

It can be difficult to test your service classes when they're being run on Tomcat and you have only your WSDL interface to deal with them through, and no easy way to see what's happening. Depending on the type of app you're writing, you might be able to include a static main() method on your classes to isolation test them using the java runtime from a console. The main method can test each of your APIs directly by instantiating the class, and each of the methods can use System.out.println()

Using MySQL

Once you have Apache HTTPD and PHPMyAdmin set up, you should be able to browse to http://localhost/phpmyadmin/index.php (or wherever else you put it) and interact with databases. PHPMyAdmin is a pretty easy to use and flexible tool. Use it to create a database, set up some tables in it etc. You can also use it to test SQL queries directly before writing Java code that uses them - a nice easy way to test that what you're actually doing is right before you spend a lot of time debugging things.

To see how to use JDBC and Connector/J, see

There is plenty of information online about SQL and how to use it, use Google.

Dealing with Axis Quirks

Usually after you deploy a service using AdminClient and a wsdd file, you will have to reload the Axis extension to Tomcat.

Dealing with Tomcat Quirks

Unlike Apache HTTPD, Tomcat's Windows app has no easy way to shut down or relaunch the service. I have not had much luck with its startup shell scripts and batch files, so I've found the only reliable way to get rid of it is to open Task Manager select the "tomcatw.exe" process and kill it (Alt+E), as well as killing the "java.exe" process.

(04/08/2004 - Ben Goodger)