Question

I copied a very basic sample from https://github.com/cgrand/enlive, but it doesn't compile:

(ns web.handler
  (:require
    [compojure.core :refer :all]
    [compojure.handler]
    [compojure.route :as route]
    [net.cgrand.enlive-html :as html]))

;; Compiler throws in the next line, see the message below.
(html/deftemplate main-template "templates/index.html"
  []
  [:head :title] (html/content "Enlive starter kit"))

(defroutes app-routes
  (GET "/" [] "Hello")
  (GET "/ping/:what" [what] (str "<h1>Ping '" what "'</h1>"))
  (route/resources "/")
  (route/not-found "Not Found"))

(def app
  (compojure.handler/site app-routes))

Error I get:

java.lang.NullPointerException, compiling:(handler.clj:9:1)

I run with command:

lein ring server-headless

How to make it work?

EDIT

My investigation so far: error throw from enlive-html.clj:54:

(defn tagsoup-parser 
 "Loads and parse an HTML resource and closes the stream."
 [stream]
  (filter map?
    (with-open [^java.io.Closeable stream stream]
      (xml/parse (org.xml.sax.InputSource. stream) startparse-tagsoup)))) ; #54 

Probably org.xml.sax is not referenced? How can I do this with lein?

Was it helpful?

Solution

That error normally happens when the template file is not found. With templates/index.html, it is looking in the resources/templates directory or in the src/templates directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top