Noir app runs well on one machine while doesn't work on the other

53 views
Skip to first unread message

Bahman Movaqar

unread,
Apr 14, 2012, 11:13:04 PM4/14/12
to clj-...@googlegroups.com
Hi all,

Following the "Getting Started" instructions on http://webnoir.org/, I managed to install noir and run my first app with a minor modification:  I added ':gen-class' to 'servlet.clj' to have a working uberjar.  Everything went fine on my laptop.  As the next step, I decided to run the *same* uberjar on my VPS and to my surprise it did *not* work!  Any URL I tried bounced back with a 404 while strangely enough the stylesheets for the 404 page were correctly loaded and the page was displayed with a dark background and a green'ish theme.   Both laptop and VPS run the same version of JDK (1.6.0_26) on Linux.  The only differences I can think of is that VPS is a 32-bit machine and has a static valid IP while the laptop is a 64-bit machine with no static valid IP.

What am I doing wrong?  Am I missing something obvious?  Any hint/help is much appreciated.

TIA,

==== project.clj ====
(defproject arvand "0.1.0-SNAPSHOT"
  :dependencies [[org.clojure/clojure "1.3.0"]
                 [noir "1.2.2"]]
  :uberjar-name "arvand.jar"
  :main arvand.server)

==== server.clj ====
(ns arvand.server
  (:require [noir.server :as server])
  (:gen-class))

(server/load-views "src/arvand/views/")

(defn -main [& m]
  (let [mode (keyword (or (first m) :dev))
        port (Integer. (get (System/getenv) "PORT" "8080"))]
    (server/start port {:mode mode
                        :ns 'arvand})))

==== Lein output ====
$ lein clean && lein uberjar
Copying 31 files to /home/bahman/Work/arvand/lib
Compiling arvand.server
Compilation succeeded.
Created /home/bahman/Work/arvand/arvand-0.1.0-SNAPSHOT.jar
Including arvand-0.1.0-SNAPSHOT.jar
Including tools.macro-0.1.0.jar
Including clojure-1.3.0.jar
Including core.incubator-0.1.0.jar
Including commons-fileupload-1.2.1.jar
Including hiccup-0.3.7.jar
Including servlet-api-2.5-20081211.jar
Including clj-json-0.4.3.jar
Including commons-codec-1.3.jar
Including java.classpath-0.1.0.jar
Including commons-httpclient-3.1.jar
Including noir-1.2.2.jar
Including ring-servlet-1.0.1.jar
Including tools.namespace-0.1.0.jar
Including ring-reload-modified-0.1.1.jar
Including clout-1.0.0.jar
Including ring-1.0.1.jar
Including jetty-util-6.1.25.jar
Including commons-logging-1.1.1.jar
Including jackson-core-asl-1.5.0.jar
Including jets3t-0.8.1.jar
Including servlet-api-2.5.jar
Including ring-jetty-adapter-1.0.1.jar
Including ns-tracker-0.1.1.jar
Including ring-devel-1.0.1.jar
Including jbcrypt-0.3m.jar
Including clj-stacktrace-0.2.3.jar
Including commons-io-1.4.jar
Including ring-core-1.0.1.jar
Including jetty-6.1.25.jar
Including java-xmlbuilder-0.4.jar
Including compojure-1.0.0.jar
Created /home/bahman/Work/arvand/arvand.jar

==== Output on VPS ====
$ java -jar arvand.jar
Starting server...
2012-04-15 06:38:51.940:INFO::Logging to STDERR via org.mortbay.log.StdErrLog
2012-04-15 06:38:51.941:INFO::jetty-6.1.x
2012-04-15 06:38:51.952:INFO::Started SocketC...@0.0.0.0:8080
Server started on port [8080].
You can view the site at http://localhost:8080

$ wget http://localhost:8080/
--2012-04-15 06:38:56--  http://localhost:8080/
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:8080... connected.
HTTP request sent, awaiting response... 404 Not Found
2012-04-15 06:38:56 ERROR 404: Not Found.

$ wget http://localhost:8080/welcome
--2012-04-15 06:38:56--  http://localhost:8080/welcome
Resolving localhost... ::1, 127.0.0.1
Connecting to localhost|::1|:8080... connected.
HTTP request sent, awaiting response... 404 Not Found
2012-04-15 06:38:58 ERROR 404: Not Found.


--
Bahman

Mark Rathwell

unread,
Apr 15, 2012, 12:04:16 AM4/15/12
to clj-...@googlegroups.com
Strange. Could you install lein on the VPS and try building the jar
on that machine, and then running it?

Otherwise, I would guess the problem might be something with
noir.server/load-views or
clojure.tools.namespace/find-namespaces-in-dir not working as expected
for some reason, and to test that, commenting out
(server/load-views...) and adding (require 'arvand.views.welcome)
would prove or disprove it pretty quickly.

Bahman Movaqar

unread,
Apr 15, 2012, 12:18:08 AM4/15/12
to clj-...@googlegroups.com
Thank you!  The 'require' did the trick.

Just curious:  why it worked on my laptop while on VPS it returned 404?  I don't understand it.

--
Bahman

Mark Rathwell

unread,
Apr 15, 2012, 12:22:30 AM4/15/12
to clj-...@googlegroups.com
I can't be sure without being able to reproduce the problem. It's
almost certainly something with
clojure.tools.namespace/find-namespaces-in-dir not being able to read
directories in the jar on that particular machine. Possibly that it
was compiled for 64-bit and run on 32-bit, possibly some permissions
issue. If you could build on the VPS and it works that way, that
would help answer it.

Bahman Movaqar

unread,
Apr 15, 2012, 12:24:47 AM4/15/12
to clj-...@googlegroups.com
I just built an uberjar on VPS without even the 'require' trick and it works fine.

--
Bahman

Mark Rathwell

unread,
Apr 15, 2012, 12:25:25 AM4/15/12
to clj-...@googlegroups.com
Probably the 64-bit/32-bit thing then.

Bahman Movaqar

unread,
Apr 15, 2012, 12:26:48 AM4/15/12
to clj-...@googlegroups.com
Ah!  I thought JVM is able to handle such stuff.
Thank you.

--
Bahman

Mark Rathwell

unread,
Apr 15, 2012, 12:28:35 AM4/15/12
to clj-...@googlegroups.com
Usually it can. I've run into some issues in the past, but it's been
so long I don't even remember what they were.

Mark Rathwell

unread,
Apr 15, 2012, 12:37:11 AM4/15/12
to clj-...@googlegroups.com
> Usually it can.  I've run into some issues in the past, but it's been
> so long I don't even remember what they were.

A quick search indicates that Java uses JNI is used for some file i/o,
which can be platform dependent.

Reply all
Reply to author
Forward
0 new messages