Error: Invalid or corrupt jarfile
I get an invalid or corrupt file when trying to use this.
@gaberger
More info would be appreciated, both for the maintainer and consumers. (and me being a consumer)
Perhaps post what kind of behavior you get that makes you think it is invalid or corrupt?
Here's what I would expect to work:
$ clj -A:new app jartest.core
$ cd jartest.core/
$ clj -m jartest.core
Hello, World!
$ clj -A:depstar jartest.jar
Writing jar...
$ java -jar jartest.jar -m jartest.core
Error: Invalid or corrupt jarfile jartest.jar
$ cat src/jartest/core.clj
(ns jartest.core
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"))
$ cat ~/.clojure/deps.edn
...
:new {:extra-deps {seancorfield/clj-new
{:git/url "https://github.com/seancorfield/clj-new"
:sha "108f27159501f8ce12564b398b0ea50def3892b1"}}
:main-opts ["-m" "clj-new.create"]}
;; uberjar building: clj -A:depstar result.jar
:depstar {:extra-deps
{com.healthfinch/depstar
{:git/url "https://github.com/healthfinch/depstar.git"
:sha "4aa7b35189693feebc7d7e4a180b8af0326c9164"}}
:main-opts ["-m" "hf.depstar.uberjar"]}}}
That's what the README would leave me to believe should work.
The solution is to add a manifest, manually.
Create a file manifest containing just:
Main-Class: clojure.main
Then, after building the uberjar, run this command to update the manifest:
$ jar ufm jartest.jar manifest
Now you can run it and get a REPL:
$ java -jar jartest.jar
Clojure 1.10.0-alpha8
user=>
or you can run your main namespace:
$ java -jar jartest.jar -m jartest.core
Hello, World!
$
I'll submit a PR for the README to clarify this.
Pull Request #7 is an alternative solution -- that actually adds minimal manifest support (Main-Class).
With that PR, here's the result:
$ clj -A:new app jartest.core
$ cd jartest.core/
$ clj -m jartest.core
Hello, World!
$ clj -A:depstar jartest.jar -m
Writing jar...
$ java -jar jartest.jar -m jartest.core
Hello, World!
The -m argument is short for clojure.main. Or you could do:
$ clj -A:depstar jartest.jar jartest.core
Writing jar...
$ java -jar jartest.jar
Hello, World!
I've withdrawn both of my PRs. Here's what already works with depstar without any changes:
$ clj -A:new app jartest.core
$ cd jartest.core/
$ clj -m jartest.core
Hello, World!
$ clj -A:depstar jartest.jar -m
Writing jar...
$ java -cp jartest.jar clojure.main -m jartest.core
Hello, World!
Given the update to the README (PR #8), I think this could be closed now.
Note: my fork of depstar supports manifests via pom.xml -- see https://github.com/seancorfield/depstar -- and it also fixes some bugs that can cause corrupted/invalid JAR files (due to problems handling certain input files).