This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # architecture (20)
- # beginners (140)
- # cider (155)
- # cljsjs (1)
- # cljsrn (29)
- # clojure (53)
- # clojure-dev (9)
- # clojure-italy (40)
- # clojure-nl (13)
- # clojure-poland (4)
- # clojure-russia (8)
- # clojure-uk (51)
- # clojurescript (74)
- # cursive (36)
- # data-science (1)
- # datomic (3)
- # emacs (14)
- # fulcro (11)
- # graphql (2)
- # java (21)
- # jobs (3)
- # nrepl (7)
- # off-topic (18)
- # om-next (1)
- # onyx (9)
- # portkey (8)
- # re-frame (72)
- # reagent (64)
- # reitit (4)
- # remote-jobs (1)
- # rum (1)
- # schema (1)
- # shadow-cljs (49)
- # slack-help (1)
- # spacemacs (8)
- # specter (7)
- # tools-deps (27)
- # vim (28)
I have told gradle about my local jar file and it seems to be correctly placing it in my library. However, i want to invoke the clojure functions contained inside of it.
I’m able to use invoke clojure functions just fine:
however i’m getting an error when i try to require the namespace of my library:
` The error is really clear. But i’m not sure how to troubleshoot it. I assume i should 1. figure out the classpath my java ...process is looking at. 2. understand what determines the classpath of my functions inside my jar. I understand abstractly what this all about, but the details seem to be eluding me.
Could not locate fk_gen/core__init.class or fk_gen/core.clj on classpath. Please check that namespaces with dashes use underscores in the Clojure file name.
it sounds like you have the clojure jar on the classpath, but not the jar containing your code
a jar file is just a zip file, so you should be able to unzip the jar and see what files are inside it to verify if it contains your code or not
@hiredman that sounds right. the fact it doesn’t expand in my editor is troubling lol
what do you mean? does it contain a file
fk_gen/core.clj or a file
And that JAR is on the classpath when you start your Java code? Or should I ask: how are you running your Java code?
@seancorfield I believe so, though as i said, i’m unsure of how to introspect my class path in different environments. I seem to be making progress as i pulled in the clj files for my library. Now its complaining that it can’t find the dependencies for my library 🙂.
Java doesn't like you taking shortcuts with dependencies (this is why "local JAR file" is a bad idea in nearly all cases).
@seancorfield thats possible. it occurs to me that this would need to be a uberjar (contain all the deps) for me to use it locally. But that seems to require a gen-class and a main function… which doesn’t make doesn’t make sense for a library. Do you have a suggestion on a workflow for when you want to interopt by calling clojure code from java? I tried to hit like the first 20 links and mostly got docs which didn’t seem specific answering my question of how to ‘easily’. I’m trying to rush this so I probably just need to back up and read that documentation
or maybe a uberjar doesn’t require a main entry point… i think the docs i’m reading just word things to imply it.
right, so importing the uberjar seems to be working. Which hopefully saves the demo i plan on doing tomorrow 🙂. I’ll go back and fill in the blanks later.
You can make an uberjar with zero AOT (well, except Clojure itself since that ships with part/all of it AOT'd, right?) and you can specify
clojure.main as the main entry point.
To play nice in the Java ecosystem as "just" a library JAR, you need to generate a POM with your dependencies, and have it in a Maven-like repo (or local .m2 cache) for other Java tools to use it easily.
So if you create a local JAR, you also need to create a
pom.xml, and then you could
lein-localrepo install it into
.m2 (or put it in a Maven-like shared repo), when Gradle can just be pointed at that coordinate.
If your Clojure code uses libraries from Clojars, Gradle will also need to be told to look in Clojars (as well as Maven Central).