## page was renamed from Tomcat
= Tomcat =
Apache Tomcat is an open source software implementation of the Java Servlet and JavaServer Pages technologies.
== Installation on Slackware ==
{{{#!highlight sh
cd ~/Downloads
wget http://mirrors.fe.up.pt/pub/apache/tomcat/tomcat-7/v7.0.57/bin/apache-tomcat-7.0.57.tar.gz
su
cp apache-tomcat-7.0.57.tar.gz /opt
cd /opt
tar xvzf apache-tomcat-7.0.57.tar.gz
chown vitor * -R
chgrp users * -R
exit
}}}
== Start Tomcat ==
{{{#!highlight sh
cd /opt/apache-tomcat-7.0.57/bin/
#./startup.sh
./catalina.sh start
# http://localhost:8080/
}}}
== Add admin user ==
{{{#!highlight sh
cd /opt/apache-tomcat-7.0.57/conf
}}}
Edit tomcat-users.xml
{{{
}}}
{{{#!highlight sh
./shutdown.sh
./startup.sh
}}}
== WebApps location ==
* /opt/apache-tomcat-7.0.57/webapps
A WAR file can be copied or exploded in the webapps folder.
== Sample App ==
Download http://localhost:8080/docs/appdev/sample/sample.war and deploy in the webapps folder.
After the deploy the WAR file is exploded.
== Configuration values in web.xml for WAR file ==
Adapted from http://stackoverflow.com/questions/372686/how-can-i-specify-system-properties-in-tomcat-configuration-on-startup
{{{#!highlight xml
SMTP_PASSWORD
java.lang.String
abc123ftw
}}}
Get values in code:
{{{#!highlight java
// Obtain our environment naming context
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
// Look up our data source
String s = (String)envCtx.lookup("SMTP_PASSWORD");
}}}
== Change HTTP from port 8080 to port 8081 and AJP from 8009 to 8010 ==
Edit file conf/server.xml
Change the HTTP Connector from 8080 to 8081. Change AJP1.3 connector from 8009 to 8010.
{{{#!highlight xml
}}}
== Copy JBoss5 client libs to Tomcat ==
{{{#!highlight bash
cd /opt/jboss-5.1.0.GA/client
cp commons-logging.jar /opt/apache-tomcat-7.0.53/lib
cp concurrent.jar /opt/apache-tomcat-7.0.53/lib
cp ejb3-persistence.jar hibernate-annotations.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-aop-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-appclient.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-aspect-jdk50-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-common-core.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-deployers-client-spi.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-deployers-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-deployers-core-spi.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-deployers-core.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-deployment.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ejb3-common-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ejb3-core-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ejb3-ext-api.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ejb3-proxy-clustered-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ejb3-proxy-impl-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ejb3-proxy-spi-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ejb3-security-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ha-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-ha-legacy-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-iiop-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-integration.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-j2se.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-javaee.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-jsr77-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-logging-jdk.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-logging-log4j.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-logging-spi.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-main-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-mdr.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-messaging-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-remoting.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-security-spi.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-serialization.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-srp-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-system-client.jar /opt/apache-tomcat-7.0.53/lib
cp jboss-system-jmx-client.jar /opt/apache-tomcat-7.0.53/lib
cp jbosscx-client.jar /opt/apache-tomcat-7.0.53/lib
cp jbossjts-integration.jar /opt/apache-tomcat-7.0.53/lib
cp jbossjts.jar /opt/apache-tomcat-7.0.53/lib
cp jbosssx-as-client.jar /opt/apache-tomcat-7.0.53/lib
cp jbosssx-client.jar /opt/apache-tomcat-7.0.53/lib
cp jmx-client.jar /opt/apache-tomcat-7.0.53/lib
cp jmx-invoker-adaptor-client.jar /opt/apache-tomcat-7.0.53/lib
cp jnp-client.jar /opt/apache-tomcat-7.0.53/lib
cp slf4j-api.jar /opt/apache-tomcat-7.0.53/lib
cp slf4j-jboss-logging.jar /opt/apache-tomcat-7.0.53/lib
cp xmlsec.jar /opt/apache-tomcat-7.0.53/lib
}}}
== Windows client copy ==
{{{
cd C:\appsvr\jboss-5.1.0.GA\client
copy commons-logging.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy concurrent.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy ejb3-persistence.jar hibernate-annotations.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-aop-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-appclient.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-aspect-jdk50-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-common-core.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-deployers-client-spi.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-deployers-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-deployers-core-spi.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-deployers-core.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-deployment.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ejb3-common-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ejb3-core-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ejb3-ext-api.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ejb3-proxy-clustered-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ejb3-proxy-impl-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ejb3-proxy-spi-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ejb3-security-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ha-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-ha-legacy-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-iiop-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-integration.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-j2se.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-javaee.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-jsr77-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-logging-jdk.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-logging-log4j.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-logging-spi.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-main-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-mdr.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-messaging-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-remoting.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-security-spi.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-serialization.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-srp-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-system-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jboss-system-jmx-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jbosscx-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jbossjts-integration.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jbossjts.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jbosssx-as-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jbosssx-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jmx-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jmx-invoker-adaptor-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy jnp-client.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy slf4j-api.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy slf4j-jboss-logging.jar C:\appsvr\apache-tomcat-7.0.29\lib
copy xmlsec.jar C:\appsvr\apache-tomcat-7.0.29\lib
}}}
== Windows remote debug ==
https://confluence.sakaiproject.org/display/BOOT/Setting+Up+Tomcat+For+Remote+Debugging comment
{{{
C:\tomcat\bin> tomcat5w //ES//Tomcat5
-Xdebug
-Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
}}}
Listens on port 5050:
{{{
Cmd as admin
<...>\apache-tomcat-7.0.29\bin>Tomcat7w.exe //ES//Tomcat7
Java tab
Java options:
-Xdebug
-Xrunjdwp:transport=dt_socket,address=5050,server=y,suspend=n
}}}
== Tomcat 7 - bin\catalina.bat ==
Starting with
* set JPDA_SUSPEND=y
* catalinat.bat jpda start
* Remote debug app with eclipse on port 8000. When attached the tomcat server will boot
== Linux remote debug ==
{{{#!highlight sh
export JPDA_SUSPEND=y # to wait for attach debugger
bin/catalina.sh jpda start
tail logs/catalina.out # should show Listening for transport dt_socket at address: 8000
bin/catalina.sh jpda stop
}}}
== Logging custom logger ==
Create logger
{{{#!highlight java
java.util.logging.Logger logger = java.util.logging.Logger.getLogger("TestLogger");
logger.info("Test message info level"); // logs in info level
}}}
Configure the logging properties in /conf/logging.properties
{{{
handlers = (...),.org.apache.juli.FileHandler
handlers = (...),5TestLogger.org.apache.juli.FileHandler
5TestLogger.org.apache.juli.FileHandler.level = FINE
5TestLogger.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
5TestLogger.org.apache.juli.FileHandler.prefix = TestLogger.
# configure logger level and handler
TestLogger.handlers=5TestLogger.org.apache.juli.FileHandler
TestLogger.level=INFO
}}}
When no custom handler is defined the Logger outputs to console and to catalina.out in Tomcat 7.0.X.
The root logger defines its set of handlers using '''.handlers'''.
{{{
# default handlers in tomcat 7.X, .handlers sets the handlers for the root logger
.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler
}}}
The file logging properties file is set with the system property java.util.logging.config.file (-Djava.util.logging.config.file).