Reputation: 205
So the BUILD structure are like below:
java:
/src/java/com/abc/code/Code.java
resources:
/src/resources/com/abc/code/application.properties
BUILD filegroups
filegroup(
name = "properties",
srcs = glob(["application.properties"])
visibility = ["//visibility:public"],
)
BUILD of app use filegroups as resources/classpath_resources
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",
],
)
get null
back for Code.class.getResourceAsStream("application.properties");
and after checking the generated jar, found that application.properties sits in the top /
jar tf poc_delivery_system_app.jar
META-INF/
META-INF/MANIFEST.MF
application.properties
then update the code to Code.class.getResourceAsStream("/application.properties");
which works,
The question is why application.properties
is in the top level instead of something like /com/abc/code/application.properties
Upvotes: 0
Views: 1124
Reputation: 26984
The resources have the following resource(s)
srcs = glob(["application.properties"])
So, indeed they are at the source.
If you want them in a subdirectory, place the BUILD file at $WORKSPACE/src/resources/BUILD
with
filegroup(
name = "resources",
srcs = glob(["**/*.properties"]),
)
and the java lib will then
resources = [
"//src/resources",
],
Upvotes: 1