A war file is just a zip file, so with the appropriate directory structure and web.xml, you can create it using command line tools.
Web.xml should contain at least a way to redirect your URL to your servlet.
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd"> <servlet> <servlet-name>HelloWorldServlet</servlet-name> <servlet-class>HelloWorld</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
This web.xml file should be in a folder named WEB-INF
inside your war, and the compiled java-class file should be in WEB-INF/classes
The war file should be deleted in the webapps
directory, and not in the ROOT
directory.
Tomcat will find your war file and unzip it.
If it was named "hello.war", the default context name will be "hello" and is available at http://yourhost/hello/
source share