tools-build

pbranes 2021-10-25T21:55:01.082500Z

I am trying tools.build for the first time. I have my build.clj (uberjar) from the tools.build guide and it builds the standalone jar but when I try to run the jar I get "no main manifest attribute, in C:\_Dev\atom\buildtools\target\lib1-1.1.2-standalone.jar". Do I need to modify my main program?

(ns hello
  (:require [java-time :as t]))

(defn time-str
      "Returns a string representation of a datetime in the local time zone."
      [instant]
      (t/format
        (t/with-zone (t/formatter "hh:mm a") (t/zone-id))
        instant))

(defn run [opts]
      (println "Hello world, the time is" (time-str (t/instant))))

borkdude 2021-10-25T21:56:53.082800Z

The opening paren is missing, but this is likely only a copy-paste mistake?

borkdude 2021-10-25T21:57:44.083700Z

Also you need a (:gen-class) and a -main function for a jar to be invokable

pbranes 2021-10-25T21:58:18.084300Z

Yep, just a copy-paste mistake.

borkdude 2021-10-25T22:00:00.084800Z

See here: https://clojure.org/reference/compilation#_gen_class_examples

pbranes 2021-10-25T22:00:55.085500Z

Great... that makes sense thank you!

pbranes 2021-10-25T22:48:45.087400Z

Still getting "no manifest" use tool.build to build an uberjar. I see a "Hello" class now in my target/classes directory

Apple 2021-10-26T14:32:39.090300Z

I had the same question not long ago. Two issues: :main and the symbol. I wonder in the case of specifying :main perhaps the program can take both string and symbol without much trouble and there's not gonna be much ambiguity here.

Ngoc Khuat 2021-10-29T08:08:34.098Z

I had the same issue and fixed by adding :main to uber It was a bit confusing follow the https://clojure.org/guides/tools_build bc it’s not clear how do we specify the entry point of the program. Should this be included in the tutorial?

seancorfield 2021-10-29T15:13:01.098200Z

Post on http://ask.clojure.org about it.

πŸ‘ 1
seancorfield 2021-10-25T22:52:05.087600Z

@enkidu36 Are you specifying :main to the uber task in tools.build?

seancorfield 2021-10-25T22:52:17.087800Z

Perhaps share your build.clj so we can see what you're actually running?

pbranes 2021-10-25T22:53:02.088Z

(ns build
      (:require [clojure.tools.build.api :as b]))

(def lib 'my/lib1)
(def version "1.2.4")
(def class-dir "target/classes")
(def basis (b/create-basis {:project "deps.edn"}))
(def uber-file (format "target/%s-%s-standalone.jar" (name lib) version))

(defn clean [_]
      (b/delete {:path "target"}))

(defn uber [_]
      (clean nil)
      (b/copy-dir {:src-dirs ["src" "resources"]
                   :target-dir class-dir})
      (b/compile-clj {:basis basis
                      :src-dirs ["src"]
                      :class-dir class-dir})
      (b/uber {:class-dir class-dir
               :uber-file uber-file
               :basis basis}))

seancorfield 2021-10-25T22:53:16.088200Z

You're missing :main in the uber call.

seancorfield 2021-10-25T22:53:30.088400Z

So it won't know what the main ns is.

pbranes 2021-10-25T22:57:10.088600Z

??

(b/uber {:class-dir class-dir
               :uber-file uber-file
               :basis basis :main "hello"}

seancorfield 2021-10-25T22:57:34.088800Z

You need to tell it which namespace contains your -main function.

seancorfield 2021-10-25T22:57:56.089100Z

OK, but it will need to be a symbol per the docs, not a string.

seancorfield 2021-10-25T22:58:32.089500Z

:main 'hello should work (although your hello ns as posted did not have -main in it)

pbranes 2021-10-25T22:59:25.089700Z

Yep, the original did not. trying again

pbranes 2021-10-25T23:00:06.089900Z

Yay! That was it. thx

πŸ‘πŸ» 1