Ontology Web Services Tutorial

Interoperability is based on standards, such as Web Services (WSDL) and tools to express vocabularies such as OWL. Setting the environment to create a web service with a powerful IDE like Eclipse can be sometimes tricky. This article explains how to set up the ECLIPSE IDE and how to start creating ontological web services.


It is assumed that tomcat and eclipse are installed.

  • JAVA 1.4
  • ECLIPSE (3.1 M6)
  • JENA (2.1)
  • AXIS (1.2RC3)
  • TOMCAT (5.0.28). You need 5 or greater, due to conflicting JAR problems with JENA, tomcat and axis jars. As today (May 18-2005) It should work on MAC, even if Java 1.5 is not installed, but the OS needs to be updated.

Start (test) tomcat

I will assume that the tomcat home (also called catalina home) is $CATALINA_HOME

Look under the bin directory you will see shell script to start and stop. If you want to start in debug mode type: $CATALINA_HOME/bin/catalina.sh jpda start. You have to have JAVA_HOME define and maybe JAVA_OPTS. It is better to have sh that starts and stops tomcat. For example mine looks like this:

#!/bin/sh<br />
export CATALINA_HOME=/Library/jakarta-tomcat-5.0.28<br />
export JAVA_HOME=/Library/Java/Home<br />
export JAVA_OPTS=-Xmx256M<br />
#$CATALINA_HOME/bin/catalina.sh jpda start<br />

Use JAVA_OPTS to setup JAVA memory allocation, for example: start:-Xms256M max:-Xmx512M

Setting Eclipse classpaths and files

  • Create a new JAVA project (e.g. ontservices). A src folder is created automatically
  • Import the axis folder. Right click on the project, select file system, select axis folder directory and click on finish
  • Set source output: Right click the root of the project and click on properties. Click on the Java Build Path / Source tab. Set the output of the folder to ontservices/axis/WEB-INF/classes. All you compilation units (*.class) will go to that folder.
  • Copy all the jars files that come with JENA under /axis/WEB-INF/lib
  • Set build paths: Click Java Build Path / Libraries. Add all the jars from /axis/WEB-INF/lib. Also add servlet-api.jar form the ontservices/tomcat/common/lib. You should see the following:

  • Create a package name for the web service files I will called here: org.mmi.ont.ws. It is recommended that you put here the build file to create the web service application.
  • Copy these 2 files to the src directory: i18n_ja.properties, i18n.properties. These come with AXIS and are located at /axis/WEB-INF/classes. Because when eclipse deploys it will copy this files under /axis/WEB-INF/classes. Sometimes it deletes them. (for example when you clean the project). Th package explorere looks something like this:
  • If you want to test some samples that come with AXIS, copy the samples file that come with AXIS under the src folder. So you can test any given sample service.

Setting AXIS

Follow the instruction of AXIS installation. Basically you need to put the folder axis under the tomcat webapps folder. Check for the port. If you type your host:port/axis you should see the welcome page (e.g. http://localhost:9600/axis/). In this example I put AXIS under a different folder (under my project in ECLISE) and create a context in the Tomcat server. This is done by creating a file under $CATALINA_HOME/conf/Catalina/localhost with the context information:

&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;Context path=&quot;/axis&quot; docBase=&quot;/Users/bermudez/Documents/workspace/ontservice/axis&quot; reloadable=&quot;true&quot;/&gt;

From the context file you can see that my workspace is outside form eclipse. This is an option you can always change. Is the place where eclipse stores your projects.

Setting Ant tasks in Eclipse

Ant allows to do fast deployment. It will facilitate the creation of XML schemas, stubs, etc.. to create a web service fast. Ant is build on Eclipse, so it is easy to use with-in the platform. The following are the steps:

  1. Set class paths for ANT: got to Window/Preference. Select Ant/Runtime. Click on the tab classpath select Global Entries. Add all the jars from ontservices/tomcat/webapps/axis/WEB-INF/lib. Also add the build classes folder of your project. It should look something like this:
  2. Add the tasks: Click on the tasks tab and add the first three tasks shown in the figure:

Creating the build.xml

This file does three things: 1)it creates the wsdl 2) creates java files (stubs) and deployment-undeployment.wsdd files, 3) It deploys the service (make it available in the server). See the file here. This file should go in your web service package (folder) build.xmlorg.mmi.ont.ws).

Putting all the pieces together

  • Start Tomcat
  • Create an interface where you define what the web service should do. The name of this class should be change in the build file. Here I use: org.mmi.ont.OntService
  • Create or copy (and edit if needed) the build.xml file. Edit the properties values. For example the port number, or the name of a real host, homeProject etc...
  • Go the package explorer frame. Do right click on the build.xml file. Tomcat should be running in order to deploy the web service application
  • You should see new files created or updated in the web-service package
  • If you now open: http://localhost:9600/axis/servlet/AxisServlet/ or what ever URL is your axis servlet, you should see your service and your wsdl published
  • Implement the class you define as the implementation class (see the build xml file) In this example is org.mmi.ont.ws.OntServiceImpl
  • Start and stop tomcat
  • That is all !
  • Maybe one more thing: Test it as a client (see next section)

Testing the client

Once the web service is created, deployed and the class implemented, you should test the client. To construct a client you only need two lines of code, and then invoke any method.

OntServiceService service = new OntServiceServiceLocator();<br />
OntService ontService = service.getontservice();<br />
&lt;-- invoke method as define in your interface --&gt;<br />

Additional notes

Here I presented an example of how to create a web service in a local server. (localhost). You should change the name of the real server in the build file. I always find it easier to have a server installed in my local computer and then, when the application is ready I loaded to the server. For that you create a war file with all the AXIS folder and put it in the TOMCAT server under webapps. You can add couple of lines to the build file :

...<br />
&lt;property name=&quot;war&quot; value=&quot;${homeProject}/axis-war-local/${app.name}.war&quot; /&gt;<br />
&lt;property name=&quot;axis.home&quot; value=&quot;${homeProject}/axis&quot; /&gt;

<target name="deployForServer" depends="deployLocal">
<jar destfile="${war}">
<fileset dir="${axis.home}" />