Skip to content

Instantly share code, notes, and snippets.

@greghelton
Last active May 9, 2026 12:35
Show Gist options
  • Select an option

  • Save greghelton/3678cce98e04d2ff4ba47868c0fc44a8 to your computer and use it in GitHub Desktop.

Select an option

Save greghelton/3678cce98e04d2ff4ba47868c0fc44a8 to your computer and use it in GitHub Desktop.
Running Clojure with Maven etc
(ns my-project.core
(:require [clojure.spec.alpha :as s]))
;; Define a simple spec for a 'User' map
(s/def ::name string?)
(s/def ::age int?)
(s/def ::user (s/keys :req [::name ::age]))
(defn -main [& args]
(let [valid-data {::name "Greg" ::age 30}
invalid-data {::name "Greg" ::age "thirty"}]
(println "Checking valid data:" (s/valid? ::user valid-data))
(println "Checking invalid data:" (s/valid? ::user invalid-data))
(if (s/valid? ::user valid-data)
(println "Success! Spec is working.")
(println "Failure! Spec validation failed."))))
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0
https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>myproject</groupId>
<artifactId>cloj1</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>clojure</artifactId>
<version>1.12.0</version>
</dependency>
<dependency>
<groupId>org.clojure</groupId>
<artifactId>spec.alpha</artifactId>
<version>0.6.249</version>
</dependency>
<!-- Source: https://mvnrepository.com/artifact/org.clojure/core.specs.alpha -->
<dependency>
<groupId>org.clojure</groupId>
<artifactId>core.specs.alpha</artifactId>
<version>0.5.81</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>bin/main/</sourceDirectory>
<resources>
<resource>
<directory>bin/main</directory>
<includes>
<include>**/*.clj</include>
<include>**/*.cljc</include>
<include>**/*.edn</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>clojure.main</mainClass>
<arguments>
<argument>-m</argument>
<argument>my-project.core</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>

The following commands work
mvn clean compile
java -cp "bin/main:lib/clojure-1.12.0.jar:lib/spec.alpha-0.6.249.jar:lib/core.specs.alpha-0.5.81.jar" clojure.main -m my-project.core
and
mvn exec:java -Dexec.mainClass="clojure.main" -Dexec.args="-m my-project.core"
and
mvn exec:java

Project folders -
bin/main/my_project
src/main/clojure/my_project
target/classes/my_project

jars -
lib/clojure-1.12.0.jar
lib/core.specs.alpha-0.5.81.jar
lib/spec.alpha-0.6.249.jar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment