Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use java_binary generated wrapper script without runfiles and only a _deploy.jar #25092

Open
ruddstevens opened this issue Jan 27, 2025 · 0 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request

Comments

@ruddstevens
Copy link

Description of the bug:

While java_binary creates an executable wrapper script, it is not runnable without the target runfiles being present, even if the _deploy.jar is present.

According to the documentation: https://bazel.build/reference/be/java#java_binary:

"Building the _deploy.jar target for your rule creates a self-contained jar file with a manifest that allows it to be run with the java -jar command or with the wrapper script's --singlejar option."

The problem is that the %needs_runfiles% substitution overwrites the --singlejar option.

As seen here: https://github.com/bazelbuild/rules_java/blob/master/java/bazel/rules/bazel_java_binary.bzl#L251, the toggle for the substitution is for the java runtime toolchain to exist at an absolute path. This would imply the java_binary must be built while referring to a static local JDK. While that makes sense for the bazel run use case, it ignores the --singlejar use case when used with a JAVABIN override.

Additionally, specifying --nobuild_runfile_links renders the normal bazel run use case inoperable for the wrapper script, as there are no runfiles generated at all.

I was unable to find the original reasoning for using the java runtime absolute path as the toggle for the runfiles substitution, but it seems like either the use case for the _deploy.jar with the wrapper script needs to be updated in the documentation to clarify that runfiles are always required or the substitutions in the script template updated to support the use case of a standalone _deploy.jar and the wrapper script.

Which category does this issue belong to?

Java Rules

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

git clone https://github.com/bazelbuild/examples

cd examples/java-tutorial

echo "7.4.1" > .bazelversion

export JAVA_HOME=/path/to/local/JDK/21 (openjdk 21.0.3.0.101 2024-07-16 LTS was used).

bazel build --nobuild_runfile_links :ProjectRunner :ProjectRunner_deploy.jar

bazel-bin/ProjectRunner --singlejar
bazel-bin/ProjectRunner: Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)

bazel-bin/ProjectRunner
bazel-bin/ProjectRunner: Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)

Which operating system are you running Bazel on?

OSX 14.7.2

What is the output of bazel info release?

release 7.4.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

https://github.com/bazelbuild/examples
b51e3bdd468ce8c4a516d7dca993909dcc84af32

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

This issue was reported previously here, but closed as stale: #10373

Any other information, logs, or outputs that you want to share?

No response

@iancha1992 iancha1992 added the team-Rules-Java Issues for Java rules label Jan 27, 2025
@hvadehra hvadehra added type: feature request P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed type: bug untriaged labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Rules-Java Issues for Java rules type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants