Eclipse has excellent built-in server support for Tomcat, Glassfish and others, but sometimes you want to run your web project at a local url like http://myjavaproject instead of http://localhost:8080/myjavaproject. We can do that easily in Eclipse with Ant as you’ll soon see.
Here is what we’re going for, to run our site at http://jangles as opposed to http://localhost:8080/janglesweb.
Tomcat and Apache Setup
You’ll need to add the Apache Proxy modules to use virtual hosts at port 80 in Tomcat if you’ve not already done so. I described how to do that in this NixMash post. Here is our Apache site configuration file where [TOMCAT]/webapps/jangles is our site document root.
The Ant Build File
We’re going to create an Ant build.xml file with a target area that creates a WAR file in Tomcat’s /webapps directory. Here is a ZIP of the simple build.xml used here if you wish to download it.
We run our Ant build…
and our WAR is saved in Tomcat /webapps, automatically exploded for us.
On Web Service Endpoints and Other References
As a reminder, if you’re using web services or need to use the complete url for testing, use the virtual site url. Here’s an example of a web service using the local host endpoint address.