Friday, January 05, 2007

Tomcat: Publishing My Web Service from Eclipse to Tomcat

So, now I have created a basic web service in Eclipse. I want to publish it to an Apache Tomcat server permanently, not just for testing using Eclipses Server debug mode. Fortunately, Eclipse makes this easy to export, and Tomcat makes this easy to import.

First step is to select the project in the Eclipse Project Explorer. Right-Mouse clicks on the project and choose Export. Under the export menu, choose Web/WAR File. By default, your class should appear under the Web Module, or under the drop down list. If it doesn’t, something went wrong. Choose a Destination directory (in my case, I choose C:\TEMP) and your all set.

Now, go to your Tomcat Manager URL. In my case, it is http://localhost:8080/manager/html.

Once there, I go down the about 2/3 of the page in the Upload a War file to Install section, choose Browse, go to the C:\Temp folder, and select my .WAR file. Then I select the Install button. Now, I can see the MyWebService under the list of applications. Now comes the tricky part. If I click on it, I will get a 404 Page Not Found error. The reason being, the context is set differently in the web apps web.xml file.

To find out the correct location, I go to see the WSDL file that got imported under my Tomcat webapps folder. For me, this is located at C:\Program Files\Apache Software Foundation\Tomcat 4.1\webapps\MyWebService\wsdl\MyWebService.wsdl. Once I open up this file, I get clued into the location to find my web service, which is at http://localhost:8080/MyWebService/services/MyWebService. To confirm this works, I pull the online WSDL file at http://localhost:8080/MyWebService/services/MyWebService?wsdl.

Now I am ready to move on with my RCP application since the planned exodus of Googles Web Toolkit.

3 comments:

Anonymous said...

btw, I assume you realize there's an ant task for deploying webapps to a tomcat container? (don't forget to add the start/end tags of course)

taskdef name="deploy" classname="org.apache.catalina.ant.DeployTask"

and then to deploy a war file:

deploy url="myurl" path="/myapp" war="file/mywar.war" username="" password=""

There's a similar undeploy task. For rapid testing and deployment, I've found this VERY useful (of course, being a command line person is part of that).

Anonymous said...

Thanks you really saved my day.

Java Experience said...

good tutorial. some of your readers may want to see the WAR file and deploy on their end. I have also blogged on soap web services on tomcat from where readers can get the war file for download.