Clojure + Compojure + Maven application doesn't work in Tomcat
I'm working on a simple web application written in Clojure, using the Compojure web application framework and Maven.
This is a simplified version of my servlet:
(ns core
(:use compojure.core ring.util.servlet)
(:require [compojure.route :as route])
(:gen-class :extends javax.servlet.http.HttpServlet))
(defroutes main-routes
(GET "/" _ {:status 302 :headers {"Location" "/about"}})
(GET "/about" [] "This is the about page")
(route/not-found "File not found."))
(defservice main-routes)
This works fine using Maven's Jetty goal like this:
mvn jetty:run
However, when I build a WAR from this and deploy it on a Tomcat, I always see my 404 page, i.e. "File not found.". Can you tell me why this happens?
I build the WAR as follows:
mvn package
I noticed a warning in Tomcat about duplicate servlet-api.jar, and Maven does indeed put it into WEB-INF/lib. I removed servlet-api.jar from the WAR and still get the same problem, but does this mean that something is wrong with my whole WAR packaging process?
Can this perhaps be an issue with the different URL path? When I 开发者_运维问答start a local Jetty, the URL is as follows:
http://localhost:8080/home
But if I launch it on a Tomcat, it is like this:
http://localhost:8080/myapp/home
So is the "/myapp" perhaps part of the route? How would I tackle that problem?
Look to following example - it run both in tomcat & jetty. If you use mvn jetty:run, then you need also to specify prefix that will be used (you can see this in pom.xml for war target)
Freely quoted from http://wiki.apache.org/tomcat/HowTo:
If you are using the "war" method to deploy your application:
- delete the ROOT directory
- name your war file "ROOT.war" (capitals mandatory)
- drop the ROOT.war file directly in the /webapps directory. Tomcat will automatically deploy it.
精彩评论