user477768
user477768

Reputation:

ClassNotFound Exception in Lein (can't compile)

I am trying to :gen-class a Servlet This is my code:

(ns test.test 
(:import (java.io PrintWriter) (javax.servlet.http HttpServlet))
(:gen-class :name test.TestServlet :extends javax.servlet.http.HttpServlet))

(defn -doGet[request response]
    (let [wrtr (.getWriter response)]
        (.println wrtr "hello from clojure")))

it can't be compiled by Lein it said Exception in thread "main" java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet (Test.clj:1)

I already modified the :library-path in Lein as ":library-path "/home/long/workspaces/spring/LongHDi/war/WEB-INF/lib" but it didn't work.

Do you have any idea why?

I am trying to work with Google App Engine. The servlet class I want to extend is already in the lib folder I specified.

Upvotes: 0

Views: 1370

Answers (1)

Nicolas Modrzyk
Nicolas Modrzyk

Reputation: 14197

Which version of lein are you using ?

I downloaded jetty from here, and lein version1 worked for me with project.clj

(defproject st2 "1.0.0-SNAPSHOT"
 :description "FIXME: write description"
 :library-path "/Users/Niko/Downloads/jetty-hightide-8.1.7.v20120910/lib"
 :aot [st2.core]
 :dependencies [[org.clojure/clojure "1.3.0"]])

with st2.core the same as your code:

(ns st2.core
 (:import (java.io PrintWriter) (javax.servlet.http HttpServlet))
 (:gen-class :name test.TestServlet :extends javax.servlet.http.HttpServlet))

(defn -doGet[request response]
  (let [wrtr (.getWriter response)]
    (.println wrtr "hello from clojure")))

If you are using lein2, :library-path is not supported so I suspect you would have to add the dependencies "a-la-maven" and add them to your project dependencies.

Upvotes: 1

Related Questions