Leiningen plugin to produce OTF-compiled uberjars. (OTF = on-the-fly)
An uberjar's main class must be AOT-compiled for the jar to work as an executable. Since AOT compilation is infectious (or "transitive"), most or all of the jar is also AOT'd, along with any linked libraries. This reduces portability.
lein-otf works by injecting a sacrificial Java loader class. This class
inspects the JAR's manifest file for an attribute (injected when the JAR was
created) bearing the name of the
:main namespace then calls that namespace's
-main (or other explicitly named) function. Because the loader is not
statically linked against the rest of your codebase, AOT compilation is
restricted to namespaces explicitly mentioned in
:aot (and anything they link
against, of course.)
Compatible with projects using Clojure 1.3.0 and 1.4.0. Requires Leiningen 2.0 or greater (including preview versions).
- Specify the plugin as a plugin:
:plugins [[org.clojars.llasram/lein-otf "2.1.2"]]
:gen-classout of your main namespace. Leave project.clj's
:mainpointing to it, but add
^:skip-aotmetadata on the namespace symbol.
- Run the
uberjartask, or anything else which invokes it:
$ lein uberjar
- Bugfix for Stub class visibility.
- Also pass real
lein-otf-real-main.cljresource file, supporting OTF compilation for uberjars run via the
- Switch to implementation using separated loader stub dependency and Leiningen
2 automatic hooks and middleware. Explicit
:hooksentry no longer necessary. Restore (deprecated)
uberjar-otftask as alias for
- Support/require Leiningen 2.0. Switch to hook-based invocation.
- Extends support back to projects using Clojure v1.2.0.
lein uberjar-otfcommand. Works on Clojure v1.3.0.
Copyright (C) 2012 Tim McCormack & Marshall Vandegrift
Distributed under the Eclipse Public License v1.0, the same as Clojure.
License text is provided in