404s when deploying a noir war to jetty on squeeze
Asked Answered
G

2

6

I have a feeling I've missed something obvious here, but I don't know where to start looking.

I have a fresh noir app, created thusly:

$ lein noir new hiworld

I add a new page handler to src/hiworld/server.clj:

(ns hiworld.server
  (:require [noir.server :as server]))
(server/load-views "src/hiworld/views/")

(def handler (server/gen-handler {:mode :dev
                                  :ns 'hiworld}))

I set project.clj up for ring:

(defproject hiworld "0.1.0-SNAPSHOT"
            :description "FIXME: write this!"
            :dependencies [[org.clojure/clojure "1.3.0"]
                           [noir "1.2.2-SNAPSHOT"]]
            :dev-dependencies [[lein-ring "0.5.4"]]
            :ring {:handler hiworld.server/handler}
            :main hiworld.server)

Check it works locally:

$ lein deps
$ lein ring server-headless
# elsewhere
$ curl -I localhost:3000/welcome
HTTP/1.1 200 OK
Date: Mon, 20 Feb 2012 08:51:15 GMT
Set-Cookie: ring-session=ef00a7ad-2061-4026-9d94-3ed86ec8c46c;Path=/
Content-Type: text/html; charset=utf-8
Content-Length: 0
Server: Jetty(6.1.25)

I build a war:

$ lein ring uberwar
# builds hiworld-0.1.0-SNAPSHOT-standalone.war

All good so far. Now, I deploy it to jetty:

$ sudo apt-get install jetty libjetty-extra
$ sudo cp hiworld-0.1.0-SNAPSHOT-standalone.war /usr/share/jetty/webapps/root.war
$ sudo chown jetty:adm /usr/share/jetty/webapps/root.war
$ sudo mv /usr/share/jetty/webapps/root /usr/share/jetty/webapps/root-orig
$ sudo /etc/init.d/jetty restart

But:

$ curl -I localhost:8080/welcome
HTTP/1.1 404 Not Found
Date: Mon, 20 Feb 2012 08:59:27 GMT
Set-Cookie: ring-session=c255da15-6cbd-4d2c-8e17-9d120918bde9;Path=/
Content-Type: text/html; charset=utf-8
Content-Length: 363
Server: Jetty(6.1.24)

What did I miss? As far as I can tell, that should be all I need to do to deploy a trivial web-app to jetty, but evidently I've got something wrong here. I don't mind the restart, so I don't think I need to define my own context - or do I?

UPDATE

I've followed this sequence of instructions to create a simple "hello world" war not involving clojure at all, and it works as expected, so it would appear that there's something Not Quite Right with the clojure stack.

UPDATED AGAIN

I created the simplest possible ring app as a standalone war and deployed it. This worked, so it looks like it's something noir-specific.

UPDATED A THIRD TIME

I created and deployed a hello-world compojure app, which worked as expected.

Gidgetgie answered 20/2, 2012 at 8:44 Comment(0)
G
2

I also had this problem. I found the solution on the Noir mailing list here.

In server.clj I did two things: I removed the (server/loadviews) call, and added my views to the required namespaces.

I then built my project with the command lein ring uberwar warname.war.

Gasify answered 16/4, 2012 at 19:18 Comment(0)
M
3

In a .war file, server/load-views does not work because it cannot find physical files in the war. In hiworld/server.clj, simply require all the namespaces providing views.

This is not explained in the docs but I found a mailing list thread explaining what is wrong.

Mraz answered 14/4, 2012 at 19:33 Comment(0)
G
2

I also had this problem. I found the solution on the Noir mailing list here.

In server.clj I did two things: I removed the (server/loadviews) call, and added my views to the required namespaces.

I then built my project with the command lein ring uberwar warname.war.

Gasify answered 16/4, 2012 at 19:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.