depstar icon indicating copy to clipboard operation
depstar copied to clipboard

Error: Invalid or corrupt jarfile

Open gaberger opened this issue 7 years ago • 7 comments

I get an invalid or corrupt file when trying to use this.

gaberger avatar May 29 '18 14:05 gaberger

@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?

iku000888 avatar Jun 13 '18 14:06 iku000888

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.

seancorfield avatar Sep 23 '18 18:09 seancorfield

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.

seancorfield avatar Sep 23 '18 20:09 seancorfield

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!

seancorfield avatar Oct 11 '18 00:10 seancorfield

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!

seancorfield avatar Oct 12 '18 00:10 seancorfield

Given the update to the README (PR #8), I think this could be closed now.

seancorfield avatar Oct 19 '18 17:10 seancorfield

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).

seancorfield avatar Aug 06 '19 02:08 seancorfield