Posts Tagged ‘tomcat


Hosting a WebDAV folder using Tomcat 6

This page describes the process setting up Apache Tomcat 6 to act as a WebDAV server. After you are done you will be able to mount this WebDAV resource from windows or any other WebDAV client and modify file directly on the server. The location will look like a WebFolder to a Windows machine.

Reasons for having your webapp host WebDAV mount point

  • Allows the your users to easly upload/download documents to/from your web application.
  • Allows users to view your web application as a “Share Drive”
  • Allows you to have a “back door” into your application to view Log files.
  • Tools like “Web Drive” or “Net Drive” allow you to assign a drive letter for your application.


  • Maven installed and configured
  • Some web security knowledge- The implementation described below will allow anyone to modify files.


Start by creating a project from a maven archetype.

mvn archetype:generate -DarchetypeArtifactId=maven-archetype-webapp

Answer the rest of the questions like this…

Define value for groupId: : com.test
Define value for artifactId: : webdavTest
Define value for version:  1.0-SNAPSHOT: :
Define value for package:  com.test: :

Hit enter for the rest of the defaults.

cd to the project’s folder

Next we generate the eclipse project (optional). The project is still not ready however this step makes editing the pom.xml file easier.

mvn eclipse:clean eclipse:eclipse

Import the Existing project (generated project) into eclipse.

Next steps are to typically modify the pom.xml file and insert the rest of the dependencies and regenerate the eclipse project by re-typing the above command and clicking refresh on the eclipse project.

Your pom.xml file should look like this…


<project xmlns="" xmlns:xsi=""
  <name>webdavTest Maven Webapp</name>




Your web.xml file should look like this..


 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >

	<display-name>Archetype Created Web Application</display-name>


Test the WebDAV location

Start the tomcat server by typing

mvn tomcat:run

Navigate to the following location using your web browser to test:


if that worked then navigate using your WEBDAV client to the same location. I used windows XP and mapped a network drive. It worked fine.

if you are using linux ubuntu you can type dav://localhost:8080/webdavTest/

TODO Items

Still trying to figure out how to get Jetty server to host this site. I have tried however got an error

javax.naming.NameNotFoundException; remaining name 'Resources'
	at org.eclipse.jetty.jndi.NamingContext.lookup(
	at org.eclipse.jetty.jndi.NamingContext.lookup(
	at org.eclipse.jetty.jndi.NamingContext.lookup(

The problem was related to the following section of code: Line 262 of

  262           // Load the proxy dir context.
  263           resources = (ProxyDirContext) getServletContext()
  264               .getAttribute(Globals.RESOURCES_ATTR);
  265           if (resources == null) {
  266               try {
  267                   resources =
  268                       (ProxyDirContext) new InitialContext()
  269                       .lookup(RESOURCES_JNDI_NAME);
  270               } catch (NamingException e) {
  271                   // Failed
  272                   throw new ServletException("No resources", e);
  273               }
  274           }
  276           if (resources == null) {
  277               throw new UnavailableException("No resources");
  278           }

I think it has something to do with the difference between the Jndi Implementation available in Jetty vs the one in Tomcat 6. Sorry for the folks that are in love with jetty but for now this only works in Tomcat 6. Not sure about Websphere or other Application servers… Soon as I try I will come back to update this page.



How to get Apache Tomcat 6 to log to the console

This site is a collaborative effort! The complete text and sourcecode for this is available on GitHub. Corrections and enhancements are welcome, please make the change and submit a pull request in the comment area below.

s article explains how to get apache tomcat to log to the console (system.out).

The process is quite simple. $CATALINA_HOME represents where you have tomcat version 6 installed.

Step 1

Download Apache log4j and put it into $CATALINA_HOME/lib folder.

Step 2

Download the jar files listed below

  • tomcat-juli-adapters.jar
  • tomcat-juli.jar

You may download them from here (fool proof method):
Click on version 6 then click on Quick Navigation -> browse -> extras

Not sure if the following link will work years from now: but it shows you were the files were at the time this blog was being written.

Step 3

Put tomcat-juli.jar into your $CATALINA_HOME/bin folder and the other jar file goes into the $CATALINA_HOME/lib folder.

Step 4

Put the following file into the $CATALINA_HOME/lib folder.

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=INFO, A1

# A1 is set to be a ConsoleAppender.

# A1 uses PatternLayout.
log4j.appender.A1.layout.ConversionPattern=%d %-5p %c - %m%n


Restart the tomcat server and you should now start seeing the output to the console.

2009-09-07 10:03:45,208 WARN  org.apache.commons.digester.Digester - [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:helloWorld' did not find a matching property.
2009-09-07 10:03:45,211 INFO  org.apache.catalina.core.AprLifecycleListener - The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-sun-
2009-09-07 10:03:45,231 INFO  org.apache.coyote.http11.Http11Protocol - Initializing Coyote HTTP/1.1 on http-8080
2009-09-07 10:03:45,232 INFO  org.apache.catalina.startup.Catalina - Initialization processed in 316 ms
2009-09-07 10:03:45,254 INFO  org.apache.catalina.core.StandardService - Starting service Catalina
2009-09-07 10:03:45,255 INFO  org.apache.catalina.core.StandardEngine - Starting Servlet Engine: Apache Tomcat/6.0.18
2009-09-07 10:03:45,654 INFO  org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/helloWorld] - Initializing Spring root WebApplicationContext
2009-09-07 10:03:45,768 INFO  org.apache.coyote.http11.Http11Protocol - Starting Coyote HTTP/1.1 on http-8080
2009-09-07 10:03:45,799 INFO  org.apache.jk.common.ChannelSocket - JK: ajp13 listening on /
2009-09-07 10:03:45,803 INFO  org.apache.jk.server.JkMain - Jk running ID=0 time=0/12  config=null
2009-09-07 10:03:45,804 INFO  org.apache.catalina.startup.Catalina - Server startup in 572 ms

The logging is totally customizable. You can change the where the log output goes to or the Severity of errors that get logged by modifying the file seen above. To learn more about Apache log4j please visit the following URL:

Note that this does not replace the custom logging properties you have within your applications. You can still specify them by putting a inside your applications /WEB-INF/classes folder. This logger is only at the top level. It helps in debugging issues you may encounter with the tomcat server.

This site is a collaborative effort! The complete text and sourcecode for this is available on GitHub. Corrections and enhancements are welcome, please make the change and submit a pull request in the comment area below.

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 77 other followers

November 2017
« Oct    

Blog Stats

  • 842,358 hits