r/Clojure • • Jan 23 '26

clj-pack — Package Clojure apps into self-contained binaries without GraalVM

I built a tool to solve a problem I kept hitting: deploying Clojure apps without requiring Java on the target machine.23:20:00 [3/101]

The usual answer is GraalVM native-image, but in practice it means dealing with reflection configs, library incompatibilities, long build times, and a complex toolchain. For many projects it's more friction than it's worth.

clj-pack takes a different approach: it bundles a minimal JVM runtime (via jlink) with your uberjar into a single executable. The result is a binary that runs anywhere with zero external dependencies and full JVM compatibility — no reflection configs, no unsupported libraries, your app runs exactly as it does in development.

clj-pack build --input ./my-project --output ./dist/my-app
./dist/my-app  # no Java needed

How it works:

  • Detects your build system (deps.edn or project.clj)
  • Compiles the uberjar
  • Downloads a JDK from Adoptium (cached locally)
  • Uses jdeps + jlink to create a minimal runtime (~30-50 MB)
  • Packs everything into a single binary

The binary extracts on first run (cached by content hash), subsequent runs are instant.

Trade-off is honest: binaries are slightly larger than GraalVM output (~30-50 MB vs ~20-40 MB), and first execution has extraction overhead. But you get full compatibility and a simple build process in return.

Written in Rust, supports Linux and macOS (x64/aarch64).

https://github.com/avelino/clj-pack

Feedback and contributions welcome

72 Upvotes

17 comments sorted by

View all comments

Show parent comment

1

u/SmartLow8757 Jan 24 '26

the final "binary" is a classic self-extracting archive: a shell script (stub) concatenated with a runtime.tar.gz and the app.jar into a single chmod +x file. The stub knows the exact byte size of each segment (computed at build time), so it uses tail -c +offset | head -c size to extract each part. The runtime is generated via jlink — it analyzes which modules the JAR actually uses (jdeps --print-module-deps) and produces a minimal JVM (~30-50MB) containing only those modules, instead of a full ~300MB JDK.

On first run, the stub extracts the runtime and JAR to ~/.jbundle/cache/ keyed by a SHA256 content hash — subsequent runs skip extraction entirely and launch immediately. The exec at the end of the stub replaces the shell process with java -jar, so the binary behaves like a native executable (single PID, signals propagate correctly). It's the same trick Linux .run installers have used for decades, applied to distribute JVM apps as single-file executables.