Workaround for the time being (because of https://github.com/bazelbuild/bazel/issues/5802):
- add a new `java_library` to `src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD.tools` called "runfiles-deprecated" with a `deprecation` attribute
- change the `alias` rule in `tools/runfiles/BUILD.tools` to point to "runfiles-deprecated"
- add a new `java_library` to `tools/java/runfiles/BUILD.tools` that uses the sources from `//src/tools/runfiles/java/com/google/devtools/build/runfiles:java-srcs`. This [workaround](https://github.com/bazelbuild/bazel/issues/5803#issuecomment-411388225) is not good enough: it warns against the alias rule, not against the rule that depends on the alias, i.e. Bazel will warn against `@bazel_tools//tools/runfiles:java-runfiles`, not against the rule that depends on `@bazel_tools//tools/runfiles:java-runfiles` (as we would like to).
Clever!
move the Java runfiles library to `@bazel_tools//tools/java/runfiles`
### Description of the problem / feature request:

Every language's runfiles library is under `@bazel_tools//tools/<language>/runfiles`, Java being the only exception with `@bazel_tools//tools/runfiles:java-runfiles`.

### Feature requests: what underlying problem are you trying to solve with this feature?

Consistency with other languages.

### What's the output of `bazel info release`?

```
  $ bazel info release
release 0.16.0
```

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

https://github.com/bazelbuild/bazel/issues/5802 is not a blocker, but an annoyance, because we can't just add a `deprecation` attribute to `@bazel_tools//tools/runfiles:java-runfiles` telling users which target to use instead.
src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD.tools src/tools/runfiles/java/com/google/devtools/build/runfiles/Runfiles.java tools/BUILD tools/runfiles/BUILD.tools
src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD.tools src/tools/runfiles/java/com/google/devtools/build/runfiles/Runfiles.java tools/BUILD tools/java/BUILD tools/java/runfiles/BUILD tools/java/runfiles/BUILD.tools tools/runfiles/BUILD.tools
src/test/py/bazel/testdata/runfiles_test/bar/BUILD.mock src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock
diff --git a/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD b/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD
index 00f44a07d688e7..c988e826580808 100644
--- a/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD
+++ b/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD
@@ -29,7 +29,6 @@ filegroup(
 java_library(
     name = "runfiles",
     srcs = [":java-srcs"],
-    visibility = ["//src/tools/runfiles:__pkg__"],
 )
 
 java_test(
diff --git a/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD.tools b/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD.tools
index 5337b2b0d58fad..2f90f252ad242b 100644
--- a/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD.tools
+++ b/src/tools/runfiles/java/com/google/devtools/build/runfiles/BUILD.tools
@@ -1,5 +1,6 @@
 package(default_visibility = ["//visibility:private"])
 
+# TODO(laszlocsomor): move the sources to //tools/java/runfiles
 filegroup(
     name = "java-srcs",
     srcs = [
@@ -8,8 +9,15 @@ filegroup(
     ],
 )
 
+# TODO(laszlocsomor): after https://github.com/bazelbuild/bazel/issues/5802 is fixed, add a
+# `deprecation` attribute to @bazel_tools//tools/runfiles:java-runfiles, advising users to depend on
+# @bazel_tools//tools/java/runfiles instead. After a reasonable time (1-2 Bazel releases containing
+# the deprecation warning) remove @bazel_tools//tools/runfiles:java-runfiles.
 java_library(
     name = "runfiles",
     srcs = [":java-srcs"],
-    visibility = ["//tools/runfiles:__pkg__"],
+    visibility = [
+        "//tools/runfiles:__pkg__",
+        "//tools/java/runfiles:__pkg__",
+    ],
 )
diff --git a/src/tools/runfiles/java/com/google/devtools/build/runfiles/Runfiles.java b/src/tools/runfiles/java/com/google/devtools/build/runfiles/Runfiles.java
index 3c9eef3a6bb4fe..718b67948d8d7c 100644
--- a/src/tools/runfiles/java/com/google/devtools/build/runfiles/Runfiles.java
+++ b/src/tools/runfiles/java/com/google/devtools/build/runfiles/Runfiles.java
@@ -35,7 +35,7 @@
  *   java_binary(
  *       name = "my_binary",
  *       ...
- *       deps = ["@bazel_tools//tools/runfiles:java-runfiles"],
+ *       deps = ["@bazel_tools//tools/java/runfiles"],
  *   )
  * </pre>
  *
diff --git a/tools/BUILD b/tools/BUILD
index 619257122f86d4..14aa2925e7f96b 100644
--- a/tools/BUILD
+++ b/tools/BUILD
@@ -19,6 +19,7 @@ filegroup(
         "//tools/build_defs/repo:srcs",
         "//tools/build_rules:srcs",
         "//tools/coverage:srcs",
+        "//tools/java:srcs",
         "//tools/jdk:srcs",
         "//tools/launcher:srcs",
         "//tools/def_parser:srcs",
@@ -57,6 +58,7 @@ filegroup(
         "//tools/cpp:srcs",
         "//tools/cpp/runfiles:embedded_tools",
         "//tools/genrule:srcs",
+        "//tools/java:embedded_tools",
         "//tools/j2objc:srcs",
         "//tools/jdk:package-srcs",
         "//tools/jdk:srcs",
diff --git a/tools/java/BUILD b/tools/java/BUILD
new file mode 100644
index 00000000000000..36b5f634475ab4
--- /dev/null
+++ b/tools/java/BUILD
@@ -0,0 +1,17 @@
+package(default_visibility = ["//visibility:private"])
+
+filegroup(
+    name = "srcs",
+    srcs = [
+        "BUILD",
+        "//tools/java/runfiles:srcs",
+    ],
+    visibility = ["//tools:__pkg__"],
+)
+
+filegroup(
+    name = "embedded_tools",
+    srcs = ["//tools/java/runfiles:embedded_tools"],
+    visibility = ["//tools:__pkg__"],
+)
+
diff --git a/tools/java/runfiles/BUILD b/tools/java/runfiles/BUILD
new file mode 100644
index 00000000000000..a0d2c018af6ec0
--- /dev/null
+++ b/tools/java/runfiles/BUILD
@@ -0,0 +1,16 @@
+package(default_visibility = ["//visibility:private"])
+
+filegroup(
+    name = "srcs",
+    srcs = [
+        "BUILD",
+        "BUILD.tools",
+    ],
+    visibility = ["//tools/java:__pkg__"],
+)
+
+filegroup(
+    name = "embedded_tools",
+    srcs = ["BUILD.tools"],
+    visibility = ["//tools/java:__pkg__"],
+)
diff --git a/tools/java/runfiles/BUILD.tools b/tools/java/runfiles/BUILD.tools
new file mode 100644
index 00000000000000..011a549ba3381e
--- /dev/null
+++ b/tools/java/runfiles/BUILD.tools
@@ -0,0 +1,6 @@
+alias(
+    name = "runfiles",
+    # TODO(laszlocsomor): move the sources to this package.
+    actual = "//src/tools/runfiles/java/com/google/devtools/build/runfiles",
+    visibility = ["//visibility:public"],
+)
diff --git a/tools/runfiles/BUILD.tools b/tools/runfiles/BUILD.tools
index d92852377bd766..6f107ea3e76174 100644
--- a/tools/runfiles/BUILD.tools
+++ b/tools/runfiles/BUILD.tools
@@ -1,6 +1,7 @@
 package(default_visibility = ["//visibility:public"])
 
-alias(
+java_library(
     name = "java-runfiles",
-    actual = "//src/tools/runfiles/java/com/google/devtools/build/runfiles",
+    exports = ["//src/tools/runfiles/java/com/google/devtools/build/runfiles"],
+    deprecation = "Depend on @bazel_tools//tools/java/runfiles instead. This target goes away in Bazel release 0.18.0",
 )

diff --git a/src/test/py/bazel/testdata/runfiles_test/bar/BUILD.mock b/src/test/py/bazel/testdata/runfiles_test/bar/BUILD.mock
index 930884b45a9ef9..de3a5cf9d086bf 100644
--- a/src/test/py/bazel/testdata/runfiles_test/bar/BUILD.mock
+++ b/src/test/py/bazel/testdata/runfiles_test/bar/BUILD.mock
@@ -13,7 +13,7 @@ java_binary(
     srcs = ["Bar.java"],
     data = ["bar-java-data.txt"],
     main_class = "Bar",
-    deps = ["@bazel_tools//tools/runfiles:java-runfiles"],
+    deps = ["@bazel_tools//tools/java/runfiles"],
 )
 
 sh_binary(
diff --git a/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock b/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock
index 42c7d842412ec5..533a7d7243daa4 100644
--- a/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock
+++ b/src/test/py/bazel/testdata/runfiles_test/foo/BUILD.mock
@@ -23,7 +23,7 @@ java_binary(
         "//bar:bar-cc",
     ],
     main_class = "Foo",
-    deps = ["@bazel_tools//tools/runfiles:java-runfiles"],
+    deps = ["@bazel_tools//tools/java/runfiles"],
 )
 
 sh_binary(
