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.xmlSo 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?
Yes
There are some examples at https://clojure.org/guides/tools_build
Thank you Alex!