Skip to content
This repository has been archived by the owner on Apr 27, 2020. It is now read-only.

Error: Invalid or corrupt jarfile #5

Open
gaberger opened this issue May 29, 2018 · 7 comments
Open

Error: Invalid or corrupt jarfile #5

gaberger opened this issue May 29, 2018 · 7 comments

Comments

@gaberger
Copy link

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

@iku000888
Copy link

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

@seancorfield
Copy link
Contributor

seancorfield commented Sep 23, 2018

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

@seancorfield
Copy link
Contributor

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants