Sep 102011
 

With no doubt for the Java web-applications development the Eclipse and Tomcat are default choices. I usually prefer to use preinstalled Tomcat, configuring Eclipse to use the already installed instance. In this case though, by default, Tomcat logging does not work. This in most of the cases is quite anoying, as we don’t want to return in the dark ages of System.out.println() (which adds another argument to Misho’s request for improving the integration between Eclipse and Tomcat).

Enabling the Logging under Tomcat, managed by Eclipse

In order to enable the logging under Tomcat, which is managed by Eclipse, are required the following steps:

  • Prepare the configuration file log4j.properties, storing it in the appropriate directory [LOG4J_PROPS_LOCATION]
  • In Eclipse, select the server in the “Servers Window” (see the picture bellow)
  • Open (F3) > Open launch configuration > Arguments > VM arguments:
  • As last argument should be added the following instructions:
-Djava.util.logging.config.file="[LOG4J_PROPS_LOCATION]/logging.properties" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager

Tomcat’s Configuration Files Location

When I’m configuring Tomcat, I prefer the configuration files to be located in the server’s directory. When the server is launched by Eclipse though, it’s not that easy.

When a server is “created” under Eclipse, using independent Tomcat installation, the physical location of its configuration files is the following directory “[ECLIPSE_WORKSPACE]/.metadata/.plugins/org.eclipse.wst.server.core". In this directory, under separate subdirectories are kept the configuration files for each of the servers “created” by Eclipse. Subdirectories are named with tmp[i], where [i] is the consecutive number of the server, depending of the order in which the servers are created. For example for the following servers:

there are the following configuration directories:

drwxrwxrwx   1 user     group           0 Aug 22 08:54 tmp0
drwxrwxrwx   1 user     group           0 Aug 22 08:55 tmp1
drwxrwxrwx   1 user     group           0 Aug 29 17:23 tmp2

Each of the folders has structure similar to the default Tomcat installation folder:

d:eclipse-workspace.metadata.pluginsorg.eclipse.wst.server.coretmp2>ls -al
total 0
drwxrwxrwx   1 user     group           0 Aug 29 17:23 .
drwxrwxrwx   1 user     group           0 Aug 29 17:23 ..
drwxrwxrwx   1 user     group           0 Aug 29 17:23 conf
drwxrwxrwx   1 user     group           0 Aug 29 17:23 logs
drwxrwxrwx   1 user     group           0 Sep  9 19:37 temp
drwxrwxrwx   1 user     group           0 Aug 29 17:23 webapps
drwxrwxrwx   1 user     group           0 Aug 29 17:23 work
drwxrwxrwx   1 user     group           0 Sep  9 13:18 wtpwebapps

Again, similarly to the standard Tomcat installation, we place the Log4J configuration file log4j.properties in the folder conf, perform the steps from the previous section and voilà, the logging is enabled.

Share Button