如何在巴泽尔指定Java Meta-Inf目录和服务?

发布于 2025-02-03 17:25:32 字数 785 浏览 2 评论 0原文

我正在尝试提供自己的system.loggerfinder的实现,据我所知,我必须在某些资源文件/resources/Meta-inf/services/java中指定类。 Lang.System $ LoggerFinder

现在,我的实现位于其自己的软件包中(包括构建文件和java_library()(通常),这与软件包&构建文件我的java_binary()生活在中。我将实现为deps添加到二进制文件的构建文件中,并确保使用//可见软件包可见:public只是为了确保这不是问题。我尝试将上述文件放入两个文件中,并使用resources = [“ Resources/Meta-Inf/services/java.lang.system $ loggerfinder”将其指定为资源文件。],但巴泽尔总是抱怨

  • 文件'//:resources/meta-inf/services/java.lang.system.system $ loggerfinder'',
  • 或者,如果我使用resources = [“ //resources/meta-inf/services/java.lang.systemqulfinder”]而不是资源目录缺少构建文件。

因此,我的问题基本上是:我必须在哪里放置资源,以及如何指定它们?如果我必须在资源中添加构建文件,我应该使用什么规则?

谢谢!

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.

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. 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

  • the file '//:resources/META-INF/services/java.lang.System$LoggerFinder' is missing,
  • or, if I use resources = ["//resources/META-INF/services/java.lang.System$LoggerFinder"] instead, that the the resource directory is missing a BUILD file.

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?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

信仰 2025-02-10 17:25:32

一种方法是在Meta-Inf文件夹中使用文件创建一个JAR文件,并将其添加为Java_library的依赖性。罐子的内容应合并。类似的东西:

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 
lt; META-INF/services/
jar -cf $@ .
""",
)

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. The contents of the jar should be merged in. Something like this:

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 
lt; META-INF/services/
jar -cf $@ .
""",
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文