This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-22
Channels
- # aleph (5)
- # announcements (9)
- # babashka (9)
- # beginners (127)
- # cherry (1)
- # cider (48)
- # clj-kondo (5)
- # cljdoc (1)
- # clojure (70)
- # clojure-berlin (1)
- # clojure-europe (57)
- # clojure-france (2)
- # clojure-germany (1)
- # clojure-nl (2)
- # clojure-norway (4)
- # clojure-uk (1)
- # clojurescript (2)
- # css (1)
- # cursive (6)
- # emacs (6)
- # gratitude (1)
- # honeysql (5)
- # introduce-yourself (5)
- # jobs-discuss (7)
- # joyride (1)
- # kaocha (3)
- # lsp (1)
- # malli (9)
- # nbb (2)
- # off-topic (91)
- # pathom (7)
- # pedestal (14)
- # re-frame (4)
- # reitit (67)
- # shadow-cljs (46)
- # spacemacs (3)
- # squint (3)
- # tools-build (14)
- # tools-deps (1)
- # vim (3)
Hi, I am trying to use the Cognitect AWS API from Java. I have this .clj
file:
(ns bhlieberman.s3.client
(:require [cognitect.aws.client.api :as aws]
[cognitect.aws.credentials :refer [basic-credentials-provider]])
(:import [javax.imageio ImageIO]
[ File BufferedInputStream]))
(gen-class
:name bhlieberman.s3.client.Client
:main false
:prefix "-"
:methods [^{:static true} [getImage [obj] void]])
(defn write-image [^BufferedInputStream is]
(-> is ImageIO/read (ImageIO/write "jpg" (File. "test.jpg"))))
(defn -getImage [obj]
(let [s3 (aws/client {:api :s3
:region "us-west-2"
:credentials-provider
(basic-credentials-provider {:access-key-id (System/getenv "AWS_ACCESS_KEY_ID")
:secret-access-key (System/getenv "AWS_SECRET_KEY")})})
opts {:op :GetObject
:request {:Bucket "images"
:Key obj}}]
(-> s3 (aws/invoke opts) :Body write-image)))
I guess I'm not sure if this is properly a tools-build
Q, but when I compile this into a .jar (compilation works fine) and put it in my build.gradle
, I can't import it as import bhlieberman.s3.client.Client
. I think I ought to be able to do that. I tried specifying the .jar itself as a Gradle dep and also the entire /target
directory. Neither works.Does the jar have classes in it?
Meaning other classes besides the gen-class
'ed Client
?
Before I switched to tools-build
for this and was just using compile
at the REPL it was outputting class files for every function in the namespace, which I understand to be the expected behavior.
These are the contents of the outputted /target
dir.
I learned about jar tf jar-file
all of about 30sec ago, but here's the output of that:
jar tf .\s3.client-0.0.1.jar
META-INF/MANIFEST.MF
bhlieberman/
META-INF/
bhlieberman/s3/
META-INF/maven/
bhlieberman/s3/client.clj
META-INF/maven/com.bhlieberman/
META-INF/maven/com.bhlieberman/s3.client/
META-INF/maven/com.bhlieberman/s3.client/pom.properties
META-INF/maven/com.bhlieberman/s3.client/pom.xml
So no classes
So how are you compiling?
clj -T:build jar
And does your build script compile classes?
I guess it does not. Do I need to add compile-clj
to my build script?
There are some examples at https://clojure.org/guides/tools_build
Thank you Alex!