hi, I need to write few Java classes to be usable from Clojure. this repo is great for start https://github.com/seancorfield/java-clojure-example but I don't know how to handle dependencies in Java code. is there a way to import packages defined in deps.edn in Java code or do I have to handle Java dependencies separately?
"doesn't work" mean that I have this deps in deps.edn:
{org.clojure/clojure {:mvn/version "1.12.0"}
io.github.humbleui/types$clojure {:mvn/version "0.2.0"}
io.github.humbleui/jwm {:mvn/version "0.4.18" :exclusions [io.github.humbleui/types]}
io.github.humbleui/skija-windows-x64 {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
io.github.humbleui/skija-linux-x64 {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
io.github.humbleui/skija-macos-x64 {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
io.github.humbleui/skija-macos-arm64 {:mvn/version "0.116.2" :exclusions [io.github.humbleui/types]}
io.github.tonsky/extend-clj {:mvn/version "0.1.0"}
when I do (:import [io.github.humbleui.skija Font Typeface]) in Clojure – it works
when I try to do import io.github.humbleui.skija.Font; in Java the info I get is: package io.github.humbleui.skija does not existhttps://clojure.org/guides/tools_build has an example of a mixed clojure and java build, I would start from there. Looks like a big difference between it and the example you are starting from is it passes the basis to the javac task
thanks! I see what was my issue, I was missing :basis key when calling javac
when I created (def basis (delay (b/create-basis {:project "deps.edn"}))) and passed it to javac it started working 🙂
The libraries in deps.edn will be put on the classpath when you launch a process using clj, and will just be available
The thing to be aware of with java is just you have much more distinction between compilation and running phases, and you'll need to make sure its dependencies are available for both (although may not be exactly the same set of deps)
yeah, they will be available when I run clj. but are they available when I compile java? without clj?
let's say there's maven repo
https://mvnrepository.com/artifact/io.github.humbleui.skija
and I want to install this package via deps.edn but later import it in Java file and compile this Java file by itself. so I want to write this in Java and access this package in Java
import io.github.humbleui.skija;
currently it doesn't work for me and I wonder whether it's doable, or do I have to create some maven project with its own dependencies?
what does "doesn't work for me" mean?
java imports classes
io.github.humbleui.skija looks like a package name (prefix of a class name) not a class
and maven group and artifact ids are a disjoint namespace from the stuff contained in the jars you get from maven