0

Suppose I am having a simple sh_binary that is invoking a Java binary that depends on JRE/JDK:

sh_binary(
  name = "tool_wrapper",
  srcs = ["tool_wrapper.sh"],
  data = ["@external//tools:binary"],
  args = ["$(location @external//tools:binary)"],
)

The script tool_wrapper.sh is simply:

!/bin/bash

$1 --help

When running bazel run //tool_wrapper everything is working. I guess it is using the system JDK. But when I am using the tool_wrapper as an executable in my rule implementation it throws the following error:

A Java Runtime Environment (JRE) or Java Development Kit (JDK)
must be available in order to run Commonapi-core-generator-linux-x86_64. No Java virtual machine
was found after searching the following locations:
/home/dirk/.cache/bazel/_bazel_dirk/4d38865db03f1bbe8153893ea6d5cf3e/external/tool/jre/bin/java
java in your current PATH

Can this be an issue because of sandboxing or is it possible that the Java binary relies on some hard coded relative paths I am not ware of?

This relates to: How to properly handle args in sh_binary target? The paths should be correct in both cases.

rumbleD5
  • 37
  • 5
  • in https://stackoverflow.com/questions/76813149/how-to-properly-handle-args-in-sh-binary-target/76816005?noredirect=1#comment135446616_76816005 changing one of the `sh_binary` to a `java_binary` seemed to work -- there could something about Commonapi-core-generator that it can't find the jre/jdk – ahumesky Aug 03 '23 at 19:30
  • Thanks for the hint! Indeed I was able to solve it by defining a `java_binary` with the main class and depending on a `java_import` that lists all prebuilt jar files. Therefore no need anymore for using the prebuilt executable files. – rumbleD5 Aug 04 '23 at 17:23
  • Gotcha, yeah if you just depend on jars from an sh_binary and try to run them, you'll have to do some wiring up to find the java toolchain from bazel, runfiles, paths, etc etc. java_binary will create a wrapper script that should do all that for you – ahumesky Aug 04 '23 at 17:51

0 Answers0