Clojure + Compojure + Maven应用程序在Tomcat中不工作 [英] Clojure + Compojure + Maven application doesn't work in Tomcat

查看:210
本文介绍了Clojure + Compojure + Maven应用程序在Tomcat中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Compojure网络应用程序框架和Maven编写了一个用Clojure编写的简单Web应用程序。



这是我的servlet的简化版本: / p>

 (ns core 
(:use compojure.core ring.util.servlet)
(:require [

(获取/)

$($ gen) _ {:status 302:headers {Location/ about}})
(GET/ about[]这是关于页面)
(route / not-found not found。))

(defservice main-routes)

使用Maven的Jetty目标工作正常:

  mvn jetty:run 
pre>

然而,当我从这里构建一个WAR并将它部署在Tomcat上时,我总是看到我的404页面,即找不到文件。你可以告诉我为什么会发生这种情况吗?



我建立WAR如下:

  mvn package 


$ b我注意到Tomcat中有关servlet-api.jar重复的警告, Maven确实把它放入WEB-INF / lib。我从WAR中删除了servlet-api.jar,但仍然得到相同的问题,但这是否意味着我的整个WAR打包过程有问题?



是不同的URL路径的问题?当我开始本地Jetty时,网址如下:



http :// localhost:8080 / home



但是如果我在Tomcat上启动它,它就像这样:



http:// localhost:8080 / myapp / home



那么/ myapp可能是路由的一部分吗?我将如何解决这个问题?

解决方案

查看下面的例子 - 它在tomcat&码头。如果您使用 mvn jetty:run ,则还需要指定要使用的前缀(您可以在 pom.xml 用于战争目标)


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)

这篇关于Clojure + Compojure + Maven应用程序在Tomcat中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆