A Leiningen 2 plugin to work with servlet-based webapps.
You may use this plugin to launch a servlet-based webapp using a suitable servlet engine adapter, or generate a war/uberwar file. Adapters for Jetty-7, Jetty-8, Jetty-9, Tomcat-7 and Tomcat-8 are provided.
NOTE: This plugin is meant only to work with servlets based web apps. For idiomatic web development using Clojure you should consider lein-ring and ring.
It takes multi-line configuration in project.clj
to use lein-servlet
. For
example, a minimal configuration might look like this:
:plugins [[lein-servlet "0.4.1"]]
:servlet {:deps [[lein-servlet/adapter-jetty7 "0.4.1"]]
:webapps {"/" {:servlets {"/*" com.myapp.WebServlet}
:public "public"}}}
Given the servlet class exists in classpath and the directory public
exists
too, when you run lein servlet run
, it starts the Jetty servlet container
with the webapp at http://localhost:3000/
In many cases you may be using lein-servlet
templates that are actually
project skeletons of several types.
You do not need to have any plugin installed to create a template. Unless you
already have a version of lein-servlet/lein-template
, the following commands
automatically download the latest version for use.
The command to create lein-servlet
project skeletons is:
lein new lein-servlet [flavor] project-name
Both flavor
and project-name
are placeholders for the actual names to be
used. Note that flavor
is optional and indicates a project type. Currently
the flavor
can be either of quercus
, railo
and struts
. See examples:
$ lein new lein-servlet foo # creates a simple Clojure/servlet webapp
$ lein new lein-servlet quercus foo # creates a Clojure/PHP webapp that uses Quercus
$ lein new lein-servlet railo foo # creates a Clojure/CFML webapp that uses Railo
$ lein new lein-servlet struts foo # creates a Clojure/Java webapp that uses Struts1
The recommended use of lein-servlet
is as a project-level plugin. Put
[lein-servlet "0.3.0"]
into the :plugins
vector of your project.clj
.
If you must use this as a user-level plugin, put [lein-servlet "0.4.1"]
into the :plugins
vector of your :user
profile.
For a detail list of all possible configuration options please check the file
sample.project.clj
.
To view the configured servlet engine:
$ lein servlet engine
To start all configured webapps using the configured servlet engine:
$ lein servlet run # opens server homepage in browser
To generate a WAR file:
$ lein servlet war # generates target/<filename>.war file with sources only
$ lein servlet uberwar # generates target/<filename>.war file with dependencies
- Shantanu Kumar (author)
- Sean Corfield
- Jürgen Hötzel (Github user juergenhoetzel)
Leiningen mailing list: https://groups.google.com/group/leiningen/
Twitter: https://twitter.com/kumarshantanu
E-mail: kumar.shantanu(at)gmail.com
Copyright © 2012-2015 Shantanu Kumar and contributors
Distributed under the Eclipse Public License, the same as Clojure.