Fork me on GitHub
#tools-deps
<
2023-05-04
>
pauld13:05:35

I can't seem to use compile-clj with certain dependencies but the project can launch the clojure repl and use the dependency as normal. I wonder if it is something to do with the fact that I'm on windows and using the scoop clojure via bash.

clj -T:build jar
Error: Could not find or load main class Dumais\AppData\Local\Temp\compile-clj6495804517722369898\compile-clj;target.classes;src;resources;C:\Users\Paul
Caused by: java.lang.ClassNotFoundException: Dumais\AppData\Local\Temp\compile-clj6495804517722369898\compile-clj;target/classes;src;resources;C:\Users\Paul
Execution error (ExceptionInfo) at clojure.tools.build.tasks.compile-clj/compile-clj (compile_clj.clj:114).
Clojure compilation failed, working dir preserved: C:\Users\Paul Dumais\AppData\Local\Temp\compile-clj6495804517722369898

pauld13:05:55

Notice how it's seems to be looking for main class that is broken by the fact that my user name has a space in it.

pauld13:05:48

This only happens when I depend on certain java dependencies found in a maven repo.

pauld15:05:34

It turns out I don't need this anyway! I wanted to call Clojure code from java but I can just do this: https://en.wikibooks.org/wiki/Clojure_Programming/Tutorials_and_Tips#Invoking_Clojure_from_Java

seancorfield17:05:45

That is horribly outdated. (most of that wiki is objectively terrible). See https://clojure.org/reference/java_interop#_calling_clojure_from_java for the up-to-date way to call Clojure from Java.

seancorfield17:05:35

(updated that Wikibooks page to link to that and remove the old clojure.lang.RT stuff)

👍 1
seancorfield17:05:49

@U0FH1UL84 ☝️:skin-tone-2:

pauld19:05:57

Does this method require a compiled clojure class?

pauld19:05:42

Nevermind, I read the docs.

pauld19:05:41

Hmm, I can't get this var to bind. I have a simple stub example in my maven project.

IFn test = Clojure.var("clojure.core", "+");
        Object testResult = test.invoke(1, 2);
The above works, but I can't figure out how to get this to work:
IFn foo = Clojure.var("com.company.test", "foo");
        Object result = foo.invoke("hi", "there");
I have test.clj file on the classpath at com/company/test.clj with this:
(ns com.company.test)

(defn foo [a b]
  (str a " " b))

seancorfield19:05:10

Are you sure your classpath for running your Java code actually includes your code?

seancorfield19:05:07

(and it would help if you provided details of exactly what "doesn't work" -- i.e., what errors you are getting on which lines of code)

pauld20:05:24

java.lang.IllegalStateException: Attempting to call unbound fn: #'com/company/teast/foo
	at clojure.lang.Var$Unbound.throwArity(Var.java:45)
	at clojure.lang.AFn.invoke(AFn.java:36)
	at clojure.lang.Var.invoke(Var.java:388)

seancorfield20:05:55

You're not requiring your namespace.

seancorfield20:05:57

Per the docs I linked to: > Functions in clojure.core are automatically loaded. Other namespaces can be loaded via require:

IFn require = Clojure.var("clojure.core", "require");
require.invoke(Clojure.read("clojure.set"));
That includes requiring your own code before calling it.

pauld20:05:47

omg, reading skill are worse than I feared! Thanks. Trying out now.

pauld20:05:56

That worked! Thanks a bunch.

1
seancorfield20:05:25

We had a bunch of legacy ColdFusion apps and this was how we were able to slowly rewrite them into Clojure from the bottom up 🙂

👍 2
pauld16:05:30

Now, I want to make an uberjar but because of the original bug I mentioned, I will have to try leiningen to make an uberjar or perhaps use maven to and embed clojure files as I already demonstrated as working. Or use a linux vm... probably several options.

pauld16:05:52

maybe there is a windows channel...