Running a binary from custom rule implementation depending on JRE/JDK doesn't find it through the PATH

88 Views Asked by At

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.

0

There are 0 best solutions below