This sample shows the necessary tooling and options for building a deployable WAR file.
Note that developing at the REPL with this sample is a bit different than usual. You must tell Pedestal what HTTP server to use. See the section "Developing Your Service" below for an example.
Pedestal requires Java 1.8+ and Servlet 3.1.0 support
Building a WAR with lein-pedestal
- Remove the container dependency (e.g. Jetty) from the
project.clj
or move it to a dedicated profile. Add a:test
dependency on Servlet-3.1. - Uncomment the WAR code changes in
server.clj
- Add the latest lein-pedestal
to the
:plugins
section in yourproject.clj
file. - Set all WAR setting in the
:pedestal
section within yourproject.clj
file.
- You must supply the
:server-ns
- this should be the namespace (as a string) where yourservlet-*
functions are located.
lein pedestal uberwar
- Copy your uberwar to you /webapps directory on your container:
cp target/war-example-0.0.1-SNAPSHOT-standalone.war /mycontainer/webapps
- Startup your container locally
- Browse to the root page and then try the about page
TODO
- Start the application:
lein run-dev
- Go to localhost:8080 to see:
Hello World!
- Read your app's source code at src/war_example/service.clj. Explore the docs of functions that define routes and responses.
- Run your app's tests with
lein test
. Read the tests attest/war_example/service_test.clj
. - Learn more! See the Links section below.
To configure logging see config/logback.xml. By default, the app logs to stdout and logs/. To learn more about configuring Logback, read its documentation.
This project is set up to exclude the HTTP server from the runtime
dependencies. That way you don't accidentally deploy all of Jetty as
jar files inside a Tomcat container! To run in dev mode, you need to
tell Pedestal which HTTP server to run. project.clj
has a profile
called "jetty" that adds a dependency on Jetty. With that profile, you
can do the usual REPL based development, but Jetty's jars won't be
included in the war file you create.
- Start a new REPL:
lein with-profile +jetty repl
- Start your service in dev-mode:
(def dev-serv (run-dev))
- Connect your editor to the running REPL session. Re-evaluated code will be seen immediately in the service.
Docker container support
- Build an uberjar of your service:
lein uberjar
- Build a Docker image:
sudo docker build -t war-example .
- Run your Docker image:
docker run -p 8080:8080 war-example
- Build and run your image:
capstan run -f "8080:8080"
Once the image it built, it's cached. To delete the image and build a new one:
capstan rmi war-example; capstan build