-
Notifications
You must be signed in to change notification settings - Fork 73
Setting Up a Tomcat Server in Eclipse
We target everything to the Java Servlet spec v2.4. Though you can use most any compliant container, we use the Tomcat 5.5 series by default. Download the latest version here:
http://tomcat.apache.org/download-55.cgi
Uncompress the software package somewhere permanent.
Under the general Eclipse "Preferences..." menu item, browse to "Server -> Runtime Environments", as shown in the following figure:
Click "Add" to add a new runtime. Select the "Apache Tomcat v5.5" runtime.
Once selected, you need to specify the path to your download of Tomcat:
We need to open the "Server" view so that we can add a new server instance. In Eclipse, select the following menu item chain "Window -> Show View -> Other... -> Server -> Servers". This should add a "Servers" tab window to your workbench. Right click in that "Servers" window, select "New -> Server". It should bring up the following dialog:
Keep the host name as "localhost", select the "Apache Tomcat v5.5 Server" as the type, name the server whatever you like ("onebusaway" perhaps?), and make sure the Server runtime you installed is selected in the drop down list. Click "Finish" and there should now be a server entry with the name you specified in the "Servers" window.
By default, Eclipse will deploy your webapp to a folder in the following location:
<path to Eclipse workspace directory>/.metadata/.plugins/org.eclipse.wst.server.core/tmp0
Since that's a little unwieldy to work with, I like to change it to something more direct. To change the location, double click on the server entry with the name you specified that should now be listed in the "Servers" window.
In the Server Locations tab, change to "Use a custom location" and select a more reasonable path (I like <path to Eclipse workspace directory>/apache-tomcat-config/server_name
myself). See as an example:
Note that to update this setting, the server must not have any projects assigned to it yet (as in the next section) and the server must be published (right click on the server entry and click "Publish").
We also recommend that you give Tomcat a large amount of time to startup, since loading the bundle can take a while. Increase the startup timeout in the Tomcat configuration page by expanding the "Timeouts" section, and change the start value to a larger number (e.g., 300 seconds).
We now want to add project modules to the server so the server can host their content. Right click on your newly created server entry and select "Add and Remove Projects..."
Add any or all of the OneBusAway webapp projects that you wish to work with.
Once you've added a few project modules to a server, it's ready to run. Right click on your server instance and you should see methods for starting and stopping the server instance, as well as running the instance in debugging mode.
When you run a server instance, an entry is actually created in the standard Eclipse Run Configurations, which controls the command line options, classpath, and other settings for running applications, unit tests, etc in Eclipse. You can specify additional command line options there to, for example, increase the amount of heap memory available to the server or define other system properties.
When the server is started, it will begin spitting out messages to the console about its startup progress. When all has gone well, you'll typically get a message like:
Oct 10, 2009 8:06:21 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 4563 ms
However, go back and check for any exceptions that might have been thrown when attempting to load the project module into the container.
If all has gone well, you should now be able to see your project at:
http://localhost:8080/name-of-project-module-here
(credit to: http://dannytsang.co.uk/installing-log4j-on-tomcat-7/)
1-Stop Tomcat server (if running)
2-Download log4j library from their website: http://www.apache.org/dyn/closer.cgi/logging/log4j/1.2.17/log4j-1.2.17.zip (or pick your version)
3-Extract and copy the jar file to the Tomcat lib directory. For example log4j-1.2.17.jar to {TOMCAT_HOME}\lib
4-Go to http://mirror.csclub.uwaterloo.ca/apache/tomcat/tomcat-7/v7.0.52/bin/extras/ Download tomcat-juli-adapters.jar and tomcat-juli.jar
5-Put tomcat-juli-adapters.jar into {TOMCAT_HOME}\lib
6-Backup tomcar-juli.jar in {TOMCAT_HOME}\bin Copy and overwrite tomcat-juli.jar in {TOMCAT_HOME}\bin
7-Remove {TOMCAT_HOME}\conf\logging.properties to prevent java.util.logging generating zero length log files
8-Create a file called log4j.properties with the following content and save it into {TOMCAT_HOME}\lib (log4j.properties can be found in oba project under java/main/resources or sample file is here: http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j
9-Start Tomcat.
These above 1 - 9 steps are not needed if you just want to use log4j in your own each web application. — In that case, just put log4j.jar and log4j.properties into WEB-INF/lib and WEB-INF/classes repectivelly of your web application.
I've experienced strange situations where Tomcat would silently fail on startup. By enabling additional logging, it's sometimes possible to see what's going on. To enable additional logging, add the following lines:
log4j.rootLogger=info, R
log4j.appender.R=org.apache.log4j.ConsoleAppender
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%-5p %-30.30c{1} %x - %m%n
to the following file in my Tomcat installation
$CATALINA_HOME/common/classes/log4j.properties (as indicated above this is Tomcat 5 dir structure).
For tomcat 7: $CATALINA_HOME/lib/log4j.properties (or use this instruction http://tomcat.apache.org/tomcat-7.0-doc/logging.html#Using_Log4j)
Have problems? Check out our Troubleshooting page to see if we have a known solution.