Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
standalone executable jar
  • Loading branch information
alandipert committed Jul 1, 2016
1 parent b400fe4 commit 8bce848
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -4,11 +4,11 @@ Tool for converting between EDN and JSON formats. Work in progress.

## Build

Build a standalone jar and run it through [ProGuard](http://proguard.sourceforge.net/):
Build, run through [ProGuard](http://proguard.sourceforge.net/), make a standalone executable jar:

boot build package
boot package

## Run

java -jar target/e2j-optimized.jar -h
echo '{:x 1 :y [1 2 3]}' | java -jar target/e2j-optimized.jar
target/e2j -h
echo '{:x 1 :y [1 2 3]}' | target/e2j
32 changes: 30 additions & 2 deletions build.boot
Expand Up @@ -2,6 +2,7 @@
:source-paths #{"src"}
:dependencies '[[alandipert/boot-yeti "1.0.0-1" :scope "test"]
[alandipert/boot-trinkets "2.0.0" :scope "test"]
[commons-io "2.5" :scope "test"]
[alandipert/yeti-lib "0.9.9.1" :scope "runtime"]
[us.bpsm/edn-java "0.4.6" :scope "runtime"]
[org.apache.commons/commons-lang3 "3.4" :scope "runtime"]])
Expand All @@ -13,6 +14,9 @@
'[boot.core :as core]
'[boot.pod :as pod])

(import 'org.apache.commons.io.IOUtils
'java.io.ByteArrayOutputStream)

(def +version+ "1.0.0")

(core/deftask string-replace
Expand Down Expand Up @@ -61,6 +65,26 @@
(core/add-resource tmp)
core/commit!)))))

(core/deftask make-executable-jar
[i input-jar NAME str "input jar name"
o output-executable NAME str "output executable name"]
(let [tmp (core/tmp-dir!)]
(with-pre-wrap [fs]
(let [in-jar (first (core/by-name [input-jar] (core/input-files fs)))]
(core/empty-dir! tmp)
(util/info "Making executable jar...\n")
(with-open [baos (ByteArrayOutputStream.)]
(.write baos (.getBytes "#!/usr/bin/env bash
exec java -jar \"$0\" \"$@\"
"))
(.write baos (IOUtils/toByteArray (io/input-stream (tmp-file in-jar))))
(let [outfile (doto (io/file tmp output-executable) io/make-parents)]
(io/copy (.toByteArray baos) outfile)
(util/dosh "/bin/chmod" "u+x" (.getAbsolutePath outfile))
(-> fs
(core/add-resource tmp)
core/commit!)))))))

(deftask build
[]
(comp (string-replace :path "e2j/core.yeti"
Expand All @@ -72,8 +96,12 @@

(deftask package
[]
(comp (proguard :config "config.pro"
(comp (build)
(proguard :config "config.pro"
:input-jar "e2j.jar"
:output-jar "e2j-optimized.jar")
(sift :include #{#"\.jar$"})
(sift :include #{#"e2j-optimized.jar$"})
(make-executable-jar :input-jar "e2j-optimized.jar"
:output-executable "e2j")
(sift :include #{#"e2j$"})
(target)))

0 comments on commit 8bce848

Please sign in to comment.