Subject: Deploy your own web application into Tomcat
Author: Linux
In response to: Configure Tomcat to survive instance reboot
Posted on: 10/12/2011 09:32:17 PM
Now, we'll install our web application and tweak the Tomcat configuration a bit. First, edit the conf/server.xml file. Look for the connector for port 8080:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
and change the port from 8080 to
80, so that your web server is accessible on the normal HTTP port. Next, find the Host tag (near the end of the file):
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
Change autoDeploy to "false". Finally, inside the <Host> tag, add a <Context> tag for your application like this:
<Context docBase="myApps.war" path="" />
Now you can close server.xml.
Next you need to build a WAR file for your application -- in Eclipse, you can do this by right-clicking on the project in Package Explorer, choosing "Export...", and choose "Web -> WAR file" from the list of export formats. Copy it to the instance using a command like this (on your local machine, not the EC2 instance):
# scp -i ~/.ec2/Tomcat2.pem myApps.war
root@INSTANCE_PUBLIC_DNS_NAME:/env
/tomcat/apache-tomcat-6.0.33/webapps/myApps.war
Next, remove the default ROOT application, or at least move it out of the way:
mv webapps/ROOT webapps/xROOT
Otherwise, Tomcat won't serve your application at the root path, even if you've configured it that way.
Finally, restart Tomcat to pick up all the changes:
bin/shutdown.sh; bin/startup.sh
>
> On 10/12/2011 09:24:18 PM
Linux wrote:
Create a file "/etc/rc.d/init.d/tomcat" with the following content:
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig: 2345 96 14
# description: The Apache Tomcat servlet/JSP container.
JAVA_HOME=/usr/java/jdk1.6.0_29
CATALINA_HOME=/env/tomcat/apache-tomcat-6.0.33
export JAVA_HOME CATALINA_HOME
exec $CATALINA_HOME/bin/catalina.sh $*
You may need to tweak JAVA_HOME and/or CATALINA_HOME, depending on exactly which versions of the Java SDK and Tomcat you installed. Next, execute these commands to set the proper permissions for your init script and enable Tomcat for auto-launch:
# chmod 755 /etc/rc.d/init.d/tomcat
# chkconfig --level 2345 tomcat on
Tomcat should now be automatically launched whenever your server restarts.
References: