There are several ways to build a WAR file. Also see the page on Eclipse.
Ant is like Make, but for Java. Instead of Makefiles, Ant uses XML files to describe build targets. You can use Ant to create a WAR from the command-line.
First, you'll need to create a directory structure and web.xml file for your project:
Put your web.xml file in web/WEB-INF. An example web.xml file is as follows:
Ant should already be installed and configured on your Debian machine if you have Tomcat installed. All you need is a build file (analogous to a Makefile). You can download one from Tomcat's website that should do the trick:
Next you need a small text file which specifies parameters to your build file. Create a file called build.properties and fill it with the following text:
Now you are ready to build your project with Ant. At the top-level directory of your project, type:
If you did everything right, you should see a new 'build' folder in your project.
Next you can produce a WAR file from your compiled code:
You should find your WAR file in the 'dist' folder.
You can now upload your war file to your Tomcat server using the Manage servlet through your browser. To make things easier, you can also have Ant deploy your WAR file to Tomcat automatically. This will save you a lot of time if you need to deploy your web app often.
To allow Ant to deploy your web app for you, you need to tell Ant your Tomcat password. You should have a username and password set in /etc/tomcat6/conf/tomcat-users.xml (you need to be root to see and edit this file). Make sure your user has a 'manager' role. Copy your Tomcat manager's username and password to your build.properties file. Also, you must specify the URL of your Manager servlet. Now you have:
Now Ant can deploy your project for you:
Your new web app will start running on Tomcat automatically.