[英]How to specify java META-INF directory and services in bazel?
I am trying to provide my own implementation of the System.LoggerFinder
and as far as I know I have to specify the class in some resource file /resources/META-INF/services/java.lang.System$LoggerFinder
.我正在尝试提供自己的
System.LoggerFinder
实现,据我所知,我必须在某些资源文件/resources/META-INF/services/java.lang.System$LoggerFinder
中指定 class 。
Now my implementation is located in its own package (Including build file and java_library()
as rule), which is different from the package & BUILD file my java_binary()
lives in. I added the implementation as deps
to the BUILD file of the binary and made sure the package is visible using //visibility:public
just to make sure that's not the problem.现在我的实现位于它自己的 package (包括构建文件和
java_library()
作为规则),这与我的java_binary()
所在的 package 和 BUILD 文件不同。我将实现作为deps
添加到二进制文件的 BUILD 文件中并确保 package 使用//visibility:public
,只是为了确保这不是问题。 I tried putting the above mentioned file into both of them and specifying it as resource file in the respective BUILD file using resources = ["resources/META-INF/services/java.lang.System$LoggerFinder"]
, but bazel always complains that either我尝试将上述文件放入它们两个中,并使用
resources = ["resources/META-INF/services/java.lang.System$LoggerFinder"]
将其指定为相应 BUILD 文件中的资源文件,但 bazel 总是抱怨任何一个
'//:resources/META-INF/services/java.lang.System$LoggerFinder'
is missing,'//:resources/META-INF/services/java.lang.System$LoggerFinder'
丢失,resources = ["//resources/META-INF/services/java.lang.System$LoggerFinder"]
instead, that the the resource directory is missing a BUILD file.resources = ["//resources/META-INF/services/java.lang.System$LoggerFinder"]
代替,则资源目录缺少 BUILD 文件。 So basically my question is: Where do I have to put the resources and how do I have to specify them?所以基本上我的问题是:我必须将资源放在哪里以及如何指定它们? If I have to add a BUILD file to the resources what rule should I use?
如果我必须将 BUILD 文件添加到资源中,我应该使用什么规则?
Thanks!谢谢!
One way to do this is to create a jar file with the files in the META-INF folder and add that as a dependency of your java_library.一种方法是使用 META-INF 文件夹中的文件创建 jar 文件,并将其添加为 java_library 的依赖项。 The contents of the jar should be merged in. Something like this:
jar 的内容应该合并进去。像这样:
java_library(
name = "lib",
srcs = [...],
deps = [":meta_inf_import"],
)
java_import(
name = "meta_inf_import",
jars = [":meta_inf.jar"],
)
genrule(
name = "gen_meta_inf",
srcs = ["java.lang.System$LoggerFinder"],
outs = ["meta_inf.jar"],
cmd = """
mkdir -p META-INF/services
cp $< META-INF/services/
jar -cf $@ .
""",
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.