Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build the war file for a Clojure Noir Web application?

I was able to use these commands to generate and run a sample web app from instrcution on this web site

https://github.com/ibdknox/lein-noir

lein new noir my-project-name
lein run

( I am using Leiningen 2.0.0-preview10 on Java 1.7.0_09 Java HotSpot(TM) Client VM )

The starter web app does run ok but I want to generate the war file which I can deploy manually to my application server (Websphere).

What command or configuration for Leingen 2 is needed to generate a war file for a Noir project?

To clarify, this command "lein new noir webpoc2" generate a noir project with this .clj file

(defproject webpoc1 "0.1.0-SNAPSHOT"
            :description "FIXME: write this!"
            :dependencies [[org.clojure/clojure "1.4.0"]
                           [noir "1.3.0-beta3"]]
            :main webpoc1.server)

If I add Ring to the cl file

:ring {
                   :handler webpoc1.server/handler

}

, and run lein ring uberwar, I get this :

Exception in thread "main" java.lang.RuntimeException: No such var: webpoc1.server/handler, compiling:(
/servlet.clj:1)
        at clojure.lang.Compiler.analyze(Compiler.java:6281)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3497)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6457)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5618)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5054)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3674)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6453)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6443)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3548)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6457)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3497)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6457)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:5618)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5054)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:3674)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6453)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6443)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.access$100(Compiler.java:37)
        at clojure.lang.Compiler$DefExpr$Parser.parse(Compiler.java:518)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6455)
        at clojure.lang.Compiler.analyze(Compiler.java:6262)
        at clojure.lang.Compiler.analyze(Compiler.java:6223)
        at clojure.lang.Compiler.compile1(Compiler.java:7030)
        at clojure.lang.Compiler.compile1(Compiler.java:7025)
        at clojure.lang.Compiler.compile(Compiler.java:7097)
        at clojure.lang.RT.compile(RT.java:387)
        at clojure.lang.RT.load(RT.java:427)
        at clojure.lang.RT.load(RT.java:400)
        at clojure.core$load$fn__4890.invoke(core.clj:5415)
        at clojure.core$load.doInvoke(core.clj:5414)
        at clojure.lang.RestFn.invoke(RestFn.java:408)
        at clojure.core$load_one.invoke(core.clj:5227)
        at clojure.core$compile$fn__4895.invoke(core.clj:5426)
        at clojure.core$compile.invoke(core.clj:5425)
        at user$eval3.invoke(NO_SOURCE_FILE:1)
        at clojure.lang.Compiler.eval(Compiler.java:6511)
        at clojure.lang.Compiler.eval(Compiler.java:6500)
        at clojure.lang.Compiler.eval(Compiler.java:6501)
        at clojure.lang.Compiler.eval(Compiler.java:6477)
        at clojure.core$eval.invoke(core.clj:2797)
        at clojure.main$eval_opt.invoke(main.clj:297)
        at clojure.main$initialize.invoke(main.clj:316)
        at clojure.main$null_opt.invoke(main.clj:349)
        at clojure.main$main.doInvoke(main.clj:427)
        at clojure.lang.RestFn.invoke(RestFn.java:421)
        at clojure.lang.Var.invoke(Var.java:419)
        at clojure.lang.AFn.applyToHelper(AFn.java:163)
        at clojure.lang.Var.applyTo(Var.java:532)
        at clojure.main.main(main.java:37)
Caused by: java.lang.RuntimeException: No such var: webpoc1.server/handler
        at clojure.lang.Util.runtimeException(Util.java:170)
        at clojure.lang.Compiler.resolveIn(Compiler.java:6740)
        at clojure.lang.Compiler.resolve(Compiler.java:6710)
        at clojure.lang.Compiler.analyzeSymbol(Compiler.java:6671)
        at clojure.lang.Compiler.analyze(Compiler.java:6244)
        ... 60 more
Subprocess failed

Since I am new to Noir (and Clojure), I am at a loss trying to figure this out

like image 944
user193116 Avatar asked Dec 06 '12 19:12

user193116


2 Answers

Answering my question/ documenting my travails in leingen noir ring dependencies for other newbies. You may generate a noir project with "lein new noir ... " command , but update these files as follows if you want a war file .

project.clj

(defproject noir3 "0.1.0-SNAPSHOT"
            :description "FIXME: write this!"
            :dependencies [[org.clojure/clojure "1.4.0"]
                           [noir "1.3.0-beta10"]
                           [hiccup "1.0.2"]
                           [cheshire "4.0.3"]
                           ]
            :plugins [[lein-ring "0.7.5"]]
            :ring {:handler noir3.server/handler}            

            :main noir3.server)

server.clj

(ns noir3.server
  (:require [noir.server :as server]))

;;(server/load-views-ns 'noir3.views)

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


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

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

Then , run the following

  1. "lein run" (check if your pages are accessible),
  2. "lein ring server" (check if your pages are accessible),
  3. and finally "lein ring war" -- you should see as war file in target dir
like image 175
user193116 Avatar answered Sep 20 '22 18:09

user193116


Have you declared the handler in webpoc1.server which you are referencing? Something like this:

(def handler
  (server/gen-handler {:mode :prod
                       :ns *ns*}))

http://www.webnoir.org/tutorials/others/ offers instructions on how to use Noir with Ring.

like image 2
ponzao Avatar answered Sep 22 '22 18:09

ponzao