# Can't find Java jar using find\_jar

**URL:** https://discourse.cmake.org/t/cant-find-java-jar-using-find-jar/6285
**Category:** Code
**Created:** [August 16, 2022, 5:04pm UTC](https://discourse.cmake.org/t/cant-find-java-jar-using-find-jar/6285 "2022-08-16T17:04:51Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mdorier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@mdorier](https://discourse.cmake.org/u/mdorier)
#### Post date: [August 16, 2022, 5:04pm UTC](https://discourse.cmake.org/t/cant-find-java-jar-using-find-jar/6285/1 "2022-08-16T17:04:51Z")

</div>

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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

### Author: ![vdamewood](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/v/7ab992/32.png) [@vdamewood](https://discourse.cmake.org/u/vdamewood)
#### Post date: [August 16, 2022, 7:49pm UTC](https://discourse.cmake.org/t/cant-find-java-jar-using-find-jar/6285/2 "2022-08-16T19:49:01Z")

</div>

> [@mdorier](#):
>
> ```auto
> 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)
> 
> ```

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

```auto
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)

```
