c++11java-native-interfacebazel

bazel c++ program which used JNI, how to deal with the path of the .jar with relative path


bazel make a bazel-bin at last, my c++ codes can't find the relative path of jar at last.

options[1].optionString = (char*)"-Djava.class.path=.:JavaNativeInterface.jar"

I try genrule in bazel, but it didn't work.


Solution

  • I chosed the environment variable way.

    In bash script, I used export JNI_JAR=/path/to/myjar.jar to set an environment virable. Of course, I will do something with the 'path' to deal with different situations.

    Then, the script will use bazel to build or test my project. So I add --action_env=XXX in .bazelrc.

    Finally, I can use getenv("JNI_JAR") to get an absolute path.