tools-deps

cjohansen 2024-04-21T07:07:15.251219Z

I'm not sure if this is possible, but I want to access a protected field in library. I thought I could add a Java class to my project in the same package and extend the relevant class. Multiple aspects of this idea may be ill conceived, but here's what I did: • Added src/a/b/c/MyClass.java • Set package a.b.c; in it • Defined public class MyClass extends LibraryClass in it • Added a method that does what I want I can start the REPL just fine, but (import 'a.b.c.MyClass) gives me a java.lang.ClassNotFoundException My main question is whether this is the right way to add a Java source to a tools.deps project, but any pointers would be appreciated 🙂

thheller 2024-04-21T09:27:01.892389Z

did you compile it? need to run javac manually (e.g. tools.build)

cjohansen 2024-04-21T09:44:27.889309Z

Aha. Where do I want the output class - same directory?

cjohansen 2024-04-21T10:21:29.819219Z

You question led me to https://clojure.org/guides/tools_build#_mixed_java_clojure_build which helps me a little further 👍

thheller 2024-04-21T10:27:00.349239Z

yeah java only loads compiled .class files on the classpath

thheller 2024-04-21T10:27:14.727359Z

although I believe an upcoming jdk gets support for loading .java files as well IIRC

cjohansen 2024-04-21T10:27:45.610909Z

Yeah, I know, but I was hoping that the Clojure tooling did some magic stuff for me 🤠

thheller 2024-04-21T10:28:03.775019Z

lein does 😉

cjohansen 2024-04-21T10:28:09.525379Z

hehe

cjohansen 2024-04-21T10:29:52.946289Z

So now I have the class in target/classes. Should I add target to my sources in deps.edn, or is this loaded by default?

thheller 2024-04-21T10:30:35.691319Z

target/classes. target alone does nothing useful

cjohansen 2024-04-21T10:30:45.790069Z

Right 😅

cjohansen 2024-04-21T10:31:26.164589Z

Success! Thanks 😊

👍 1
seancorfield 2024-04-21T18:47:44.376969Z

In future, can you please reply in threads instead of spamming the main channel with a whole bunch of conversation @thheller @christian767

👍 2