Building a WAR file
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
- Remove the container dependency (e.g. Jetty) from the
project.cljor move it to a dedicated profile. Add a
:testdependency on Servlet-3.1.
- Uncomment the WAR code changes in
- Add the latest lein-pedestal
:pluginssection in your
- Set all WAR setting in the
:pedestalsection within your
- You must supply the
:server-ns- this should be the namespace (as a string) where your
servlet-*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
Building a WAR at the REPL
Getting Started with local development, not as a WAR
- Start the application:
- Go to localhost:8080 to see:
- 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 at
- 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.
Developing your service
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:
- 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