On Fri, Dec 11, 2009 at 11:51 AM, Sean Devlin francoisdev...@gmail.com wrote:
While we're at it, how 'bout an EAR file?
Never encountered one of those before -- maybe that is a good thing! :)
After a little study, I was able to write a simple servlet, compile it
with Leiningen, and make a WAR using Maven. This might be no big news
to the Java literati in the audience, but it's all new to me. :)
I thought I'd share my notes here, in case anyone else is trying to do
the same thing. There is a copy of my work here:
http://github.com/gmfawcett/simplest
The basic recipe I followed is there, and for lazier readers it also
appears below.
Many thanks to yogthos' clojure-maven-examples, which answered many
questions (though it uses clojure-maven-plugin, and does not use
Leiningen):
http://github.com/yogthos/clojure-maven-examples
Best,
Graham
* Start a new project with Leiningen (I'm using Leiningen 1.0.1):
$ lein new simplest
* Add your servlet. I put mine in 'src/simplest/servlet.clj':
(ns simplest.servlet
(:gen-class :extends javax.servlet.http.HttpServlet))
(defn -doGet [this req resp]
...)
* Add your dependencies to the project file. I added
[javax.servlet/servlet-api 2.5].
* Set the :compile-path, so that the classfiles end up where Maven
will expect to see them:
(defproject simplest 1.0.0-SNAPSHOT
:compile-path target/classes
...)
* Compile it with Leiningen, to make sure there aren't any errors:
$ lein compile
[copy] Copying 3 files to /tmp/simplest/lib
Compiling simplest
Compiling simplest.servlet
* Add the web.xml file and whatever static resources you want under
'src/main'. I added:
src/main/webapp/WEB-INF/web.xml
src/main/webapp/index.html
My web.xml is basic:
web-app xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance;
xmlns=http://java.sun.com/xml/ns/javaee;
xmlns:web=http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd;
xsi:schemaLocation=http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd;
id=simplest
version=2.5
display-nameSimplest Clojure Servlet/display-name
servlet
servlet-namesimplest/servlet-name
servlet-classsimplest.servlet/servlet-class
/servlet
servlet-mapping
servlet-namesimplest/servlet-name
url-pattern/simplest//url-pattern
/servlet-mapping
welcome-file-list
welcome-fileindex.html/welcome-file
/welcome-file-list
/web-app
* Make your POM file for Maven:
$ lein pom
Wrote pom.xml
* Generate the WAR file:
$ lein compile; mvn war:war
$ ls target/*.war
target/simplest-1.0.0-SNAPSHOT.war
* QED!
* If you want, you can add a 'Jetty plugin' to your pom.xml. This
will enable Maven to run your servlet(s) for you in a standalone Web
server, for testing:
Edit pom.xml: see
http://github.com/gmfawcett/simplest/commit/44d978c55ae02112647a743b6f957156787fba25
$ lein compile; mvn jetty:run
# visit your servlet at http://localhost:8080/
Lacking proper Leiningen/Maven integration, it's a good idea to always
call 'lein compile' before you run a Maven command.
Best,
Graham
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en