Fork me on GitHub
#tools-build
<
2021-10-25
>
Joseph R Savoie21:10:01

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

borkdude21:10:53

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

borkdude21:10:44

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

Joseph R Savoie21:10:18

Yep, just a copy-paste mistake.

Joseph R Savoie22:10:55

Great... that makes sense thank you!

Joseph R Savoie22:10:45

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

seancorfield22:10:05

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

seancorfield22:10:17

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

Joseph R Savoie22:10:02

(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}))

seancorfield22:10:16

You're missing :main in the uber call.

seancorfield22:10:30

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

Joseph R Savoie22:10:10

??

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

seancorfield22:10:34

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

seancorfield22:10:56

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

seancorfield22:10:32

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

Joseph R Savoie22:10:25

Yep, the original did not. trying again

Joseph R Savoie23:10:06

Yay! That was it. thx

1
Apple14:10:39

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 Khuat08:10:34

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?