Tomcat

From ArchWiki
Revision as of 09:30, 27 April 2011 by Matafleur (Talk | contribs)

Jump to: navigation, search

Tango-document-new.pngThis article is a stub.Tango-document-new.png

Notes: please use the first argument of the template to provide more detailed indications. (Discuss in Talk:Tomcat#)

Tomcat is an open source java servlet container.

This document describes the steps needed to install Apache Tomcat and how to deploy 3rd party web applications in Tomcat.


Installation

# pacman -S tomcat

Post Installation

Setting Java Home

There is two Java VM in Arch: OpenJDK JVM and Sun JVM.

Edit file /etc/conf.d/tomcat,

  • If you use OpenJDK JVM, set TOMCAT_JAVA_HOME to /usr/lib/jvm/java-6-openjdk, in example:

 TOMCAT_JAVA_HOME=/usr/lib/jvm/java-6-openjdk

  • If you use Sun JVM, set TOMCAT_JAVA_HOME to /opt/java, in example:

 TOMCAT_JAVA_HOME=/opt/java

Creating an Admin user

Edit the Tomcat users file to include manager and admin roles with your favorite editor.

# vim /opt/tomcat/conf/tomcat-users.xml  

example of tomcat-users.xml file.

<?xml version='1.0' encoding='utf-8'?>
 <tomcat-users>
 <role rolename="manager"/>
 <role rolename="tomcat"/>
 <role rolename="admin"/>
 <role rolename="role1"/>
 <user username="both" password="tomcat" roles="tomcat,role1"/>
 <user username="tomcat" password="tomcat" roles="tomcat"/>
 <user username="admin" password="<your_password_here>" roles="admin,tomcat,manager"/>
 <user username="role1" password="tomcat" roles="role1"/>
 </tomcat-users> \ 


Starting Tomcat

As root or with sudo.

# /etc/rc.d/tomcat start

Successful outcome:

/etc/rc.d/tomcat start
:: Starting Tomcat                  [DONE] 


Using your favorite browser go to http://localhost:8080/ for your default Tomcat home page.

 note: If this is not working. There is a problem with Tomcat.
       Check logs from /opt/tomcat/logs/catalina.log 


Web application deployment

Download the web application that you want to deploy ( a war file ) and save it to /opt/tomcat/webapps/ folder.

Restart Tomcat:

# /etc/rc.d/tomcat restart

Go to http://localhost:8080/manager/html

Tomcat will ask for your admin <username> and <password>.

Login and check that your war file is listed in the Applications.

If it is listed, click on it to access it.

Hint: Bookmark the webpage for later use.


Problems in deployment

Tomcat should automatically deploy your war file if it is in the /opt/tomcat/webapps/ folder.

If this is not happening you could try to deploy manually.

In the manager page under Deploy click on the "Select WAR file to upload" and select the war file then click on "Deploy".


How to stop Tomcat

As root or with sudo.

# /etc/rc.d/tomcat stop


How to make Tomcat start automatically

add Tomcat in to your /etc/rc.conf DAEMONS line

DAEMONS=(... @tomcat)