Java 为什么bazel要将资源从子目录复制到jar的顶层

Java 为什么bazel要将资源从子目录复制到jar的顶层,java,resources,bazel,filegroup,Java,Resources,Bazel,Filegroup,因此,构建结构如下所示: 爪哇: 资源: /src/resources/com/abc/code/application.properties 生成文件组 filegroup( name = "properties", srcs = glob(["application.properties"]) visibility = ["//visibility:public"], ) 应用程序的构建 将文件组用作资源

因此,构建结构如下所示:

爪哇:

资源:

/src/resources/com/abc/code/application.properties
生成文件组

filegroup(
    name = "properties",
    srcs = glob(["application.properties"])
    visibility = ["//visibility:public"],
)
应用程序的构建 将文件组用作资源/类路径\资源

java_binary(
    name = "app",
    classpath_resources = [
        "//src/resources/com/abc/code:properties",
    ],
    # resources = [
    #     "//src/resources/com/abc/code:properties",
    # ],
    main_class = "com.abc.code.Code",
    runtime_deps = [
        ":app_bin",
    ],
)

srcs = glob(["application.properties"])
获取
code.class.getResourceAsStream(“application.properties”)的
null
返回

检查生成的jar后,发现application.properties位于顶部
/

jar tf poc_delivery_system_app.jar
然后将代码更新为
code.class.getResourceAsStream(“/application.properties”)哪个有效


问题是为什么
application.properties
位于顶层而不是
/com/abc/code/application.properties

这些资源具有以下资源

因此,它们确实在源头

如果要将它们放在子目录中,请将生成文件放置在
$WORKSPACE/src/resources/BUILD
中,并使用

filegroup(
  name = "resources",
  srcs = glob(["**/*.properties"]),
)
然后java库将

  resources = [
     "//src/resources",
  ],

你的问题是什么?更新了@tgdaviesSo问题的标题应该是“为什么bazel要将资源从子目录复制到jar的顶层”?
classpath_resources
的文档中说“必须位于java树根目录的资源列表”()。您确定使用
resources
属性看到了相同的行为吗?
filegroup(
  name = "resources",
  srcs = glob(["**/*.properties"]),
)
  resources = [
     "//src/resources",
  ],