If you’re interested in making a commercial grade Clojure web app that deploys as a Docker container, this is the tutorial for you.
Prerequisites: You will need Leiningen and Docker installed.
First step needed is to create a Clojure web app template project. I used the following command.
lein new luminus mywebapp +reitit +http-kit +mysql +swagger +auth
This creates a Clojure web app using the Luminus Framework, Reitit for mapping of incoming requests to the proper handlers, HTTP Kit for HTTP handling, MySQL for JDBC connections to our MySQL database, Swagger for API support, and Buddy for authentication middleware. Your new web app is in the directory,
Continue reading “Clojure Docker Web Apps”
Yes, you can write Java Servlets in Clojure.
Create a Clojure Servlet project with the following command.
lein new luminus my-clj-servlet +war
The important parts of the command are ‘luminus’, which is the framework used to create the Servlet, and ‘+war’, which adds uberwar and Servlet routes to the project. This creates a file called ‘handler.clj’ that replaces the traditional Java Servlet file. The configurations for the Clojure Servlet are found in ‘project.clj’ in the
:uberwar section of the configurations.
By default the lein command above creates a project that will build a WAR file called my-clj-servlet.war, and when deployed will deploy in the my-clj-servlet context, meaning on a default installation of Tomcat you would find the link at http://localhost:8080/my-clj-servlet/
It is important to note that the resulting project from the above lein command actually won’t work as a Servlet, yet. But, we’ll fix that below. The project is configured in the hopes that you can run it from a Servlet container or as a standalone app, and with some massaging, you could. However, this tutorial only focuses on how to get the project compiling as a Java Servlet written in Clojure. If there is enough interest, I’ll write another tutorial on how to get the default project working as a standalone app, and a Servlet.
Continue reading “Java Servlets Written in Clojure”