Clojure + Compojure + Maven application doesn't work in Tomcat

本小妞迷上赌 提交于 2019-12-10 08:59:28

问题


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?


回答1:


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)




回答2:


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.


来源:https://stackoverflow.com/questions/5354038/clojure-compojure-maven-application-doesnt-work-in-tomcat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!