open-quantum-safe / liboqs-java

liboqs-java is an open source Java wrapper for the liboqs C library. The Open Quantum Safe (OQS) project provides software for prototyping quantum-resistant cryptography.
https://openquantumsafe.org
MIT License
37 stars 24 forks source link

JAVA_HOME is set, but jni.h not found #14

Closed taimoorgit closed 3 years ago

taimoorgit commented 3 years ago

Hello,

I am trying to build the Maven package on WSL/Ubuntu. I have liboqs installed with shared libs enabled. I have installed JDK 11 and set my JAVA_HOME environment variable, but it seems like jni.h still isn't found. Is there a step I am missing that can fix this?

taimoor@GAMING-PC:~/liboqs-java$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal
taimoor@GAMING-PC:~/liboqs-java$ java --version
openjdk 11.0.10 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-Ubuntu-0ubuntu1.20.04)
OpenJDK 64-Bit Server VM (build 11.0.10+9-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
taimoor@GAMING-PC:~/liboqs-java$ echo $JAVA_HOME && ls $JAVA_HOME
/usr/lib/jvm/java-1.11.0-openjdk-amd64
bin  conf  docs  legal  lib  man  release
taimoor@GAMING-PC:~/liboqs-java$ mvn package -P linux -Dliboqs.include.dir="/usr/local/include" -Dliboqs.lib.dir="/usr/local/lib"
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.openquantumsafe:liboqs-java >-------------------
[INFO] Building liboqs-java: Java wrapper for liboqs 1.0
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:3.0.0:run (default) @ liboqs-java ---
[INFO] Executing tasks
[INFO] Executed tasks
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ liboqs-java ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ liboqs-java ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- native-maven-plugin:1.0-alpha-9:initialize (generate-shared-oqs-library) @ liboqs-java ---
[INFO]
[INFO] --- native-maven-plugin:1.0-alpha-9:compile (generate-shared-oqs-library) @ liboqs-java ---
[INFO] /bin/sh -c cd '/home/taimoor/liboqs-java' && 'gcc' '-I/usr/lib/jvm/java-1.11.0-openjdk-amd64/include' '-I/usr/lib/jvm/java-1.11.0-openjdk-amd64/include/linux' '-fPIC' '-Wall' '-O3' '-I/usr/local/include' '-I/home/taimoor/liboqs-java/src/main/c' '-I/home/taimoor/liboqs-java/target/generated-sources/annotations' '-o/home/taimoor/liboqs-java/target/objs/handle.o' '-c' '/home/taimoor/liboqs-java/src/main/c/handle.c'
In file included from /home/taimoor/liboqs-java/src/main/c/handle.c:1:
/home/taimoor/liboqs-java/src/main/c/handle.h:4:10: fatal error: jni.h: No such file or directory
    4 | #include <jni.h>
      |          ^~~~~~~
compilation terminated.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.905 s
[INFO] Finished at: 2021-03-27T11:21:45-04:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:native-maven-plugin:1.0-alpha-9:compile (generate-shared-oqs-library) on project liboqs-java: Error executing command line. Exit code:1 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Thank you

taimoorgit commented 3 years ago
taimoor@GAMING-PC:~/liboqs-java$ mvn --version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 11.0.10, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.4.72-microsoft-standard-wsl2", arch: "amd64", family: "unix"
jimouris commented 3 years ago

Hi! In my system, for Java 8 JNI is located in /usr/lib/jvm/java-1.8.0-openjdk-amd64/include and for Java 11 in /usr/lib/jvm/java-11-openjdk-amd64/include. For instance:

❯❯ ~ ls $JAVA_HOME/include
classfile_constants.h  jawt.h  jdwpTransport.h  jni.h  jvmticmlr.h  jvmti.h  linux

From your logs,

taimoor@GAMING-PC:~/liboqs-java$ echo $JAVA_HOME && ls $JAVA_HOME
/usr/lib/jvm/java-1.11.0-openjdk-amd64
bin  conf  docs  legal  lib  man  release

it doesn't seem you have the include directory.

Can you try installing the following packages? apt install openjdk-11-jdk, apt install openjdk-11-jre, and apt install build-essential I think the first one will do the work but if it doesn't, try installing the other two as well. Then check if you have the include directory and inside the directory a jni.h header file.

taimoorgit commented 3 years ago

Thanks @jimouris, my issue was completely irrelevant to liboqs-java, I feel silly!

After installing the JRE in addition to the JDK I already have mvn package works fine!