Can't find Java jar using find_jar

I’m using the FindJava and UseJava modules to build a Java binding for a C++ project.
The Java binding requires to import external Java packages (namely, the YCSB “core” jar), which I have installed with spack. The following piece of code works fine:

add_jar (HelloWorldJNI
         VERSION 0.0.1
         ENTRY_POINT com.mdorier.jni.HelloWorldJNI
         GENERATE_NATIVE_HEADERS HelloWorldJNI-native
         SOURCES src/java/com/mdorier/jni/HelloWorldJNI.java
         INCLUDE_JARS /projects/spack/opt/spack/linux-ubuntu22.04-sandybridge/gcc-11.2.0/ycsb-0.17.0-3cfjcubllp2zp4jvk7saiwaqilvbof6p/core/target/core-0.17.0.jar)

But now obviously I would like cmake to find the jar for me, not have to hard-code a path like that (or even provide it as argument). However I can’t understand how to make find_jar work. This piece of code, for instance, doesn’t find the jar:

find_jar (YCSB_JAR core-0.17.0.jar PATHS /projects/spack/opt/spack/linux-ubuntu22.04-sandybridge/gcc-11.2.0/ycsb-0.17.0-3cfjcubllp2zp4jvk7saiwaqilvbof6p/core/target)

(YCSB_JAR is set to YCSB_JAR-NOTFOUND)

I have also tried using find_jar(YCSB_JAR core-0.17.0.jar PATHS ENV CLASSPATH), but it doesn’t work either.

How can I make this work?

Drop the .jar from the name you’re searching for:

find_jar (YCSB_JAR core-0.17.0 PATHS /projects/spack/opt/spack/linux-ubuntu22.04-sandybridge/gcc-11.2.0/ycsb-0.17.0-3cfjcubllp2zp4jvk7saiwaqilvbof6p/core/target)