如何使用buildr将html文件打包成jar/war?

发布于 2024-10-31 18:32:03 字数 284 浏览 5 评论 0原文

我正在开发一个嵌入式 Jetty + Wicket 应用程序,并且正在使用 buildr。目前,Buildr 未将 HTML 文件(位于主源文件夹中,与我的 *.java 文件一起)包含在 jar 中。我如何告诉构建器将它们包含在编译/打包步骤中?

感谢您的建议,我想我已经很接近了。也许我应该问的问题是如何将 .HTML 文件放入 target/classes/ 子目录中的正确位置?我已经确认,如果我可以在 target/classes 文件夹中获取 .html 文件,则 package(:jar) 会将它们存档。我要开始看看这个。

I'm working on an embedded Jetty + Wicket app and I'm using buildr. Right now, Buildr isn't including the HTML files (which are in the main source folder, alongside my *.java files) in the jar. How can I tell buildr to include them in the compilation/package step?

Thanks for the suggestions, I think I'm close. Maybe the question I should be asking is how to get the .HTML files into the right place in the target/classes/ subdirectory? I've confirmed that if I can get the .html files in the target/classes folder, package(:jar) archives them. I'm going to start looking at that.

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

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

发布评论

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

评论(3

情深如许 2024-11-07 18:32:03

感谢您的建议,我想我已经接近了。也许我应该问的问题是如何将 .HTML 文件放入 target/classes/ 子目录中的正确位置?我已经确认,如果我可以在 target/classes 文件夹中获取 .html 文件,则 package(:jar) 会将它们存档。我要开始研究这个。

听起来您想要做的就是将 java 源路径视为资源路径。这是我如何做到这一点在一个已经相当大的项目中,我将其转换为 buildr:

# Uses before_define to default all projects to including their resources from
# src/main/java instead of src/main/resources (& similar for test) if
# those source directories exist
module InlineResources
  include Buildr::Extension

  before_define do |p|
    [
      [p.resources, p._("src/main/java")],
      [p.test.resources, p._("src/test/java")]
    ].each do |res, path|
      if File.exist?(path)
        res.from(path).exclude("**/*.java")
      end
    end
  end
end

class Buildr::Project
  include InlineResources
end

这会将 *.html 文件放入 target/resources 中,然后将它们添加到包中。

Thanks for the suggestions, I think I'm close. Maybe the question I should be asking is how to get the .HTML files into the right place in the target/classes/ subdirectory? I've confirmed that if I can get the .html files in the target/classes folder, package(:jar) archives them. I'm going to start looking at that.

It sounds like what you want to do, then, is treat the java source paths as resource paths. Here's how I do that in a project I converted to buildr after it was already pretty large:

# Uses before_define to default all projects to including their resources from
# src/main/java instead of src/main/resources (& similar for test) if
# those source directories exist
module InlineResources
  include Buildr::Extension

  before_define do |p|
    [
      [p.resources, p._("src/main/java")],
      [p.test.resources, p._("src/test/java")]
    ].each do |res, path|
      if File.exist?(path)
        res.from(path).exclude("**/*.java")
      end
    end
  end
end

class Buildr::Project
  include InlineResources
end

This will put the *.html files in target/resources and from there they will be added to the package.

何以心动 2024-11-07 18:32:03

Buildr 将 src/main/webapp 文件夹中的内容作为 war 文件内容。您需要将 html 文件保留在其中。

Buildr take contents in src/main/webapp folder for war file contents. You need to keep the html files inside that.

贪了杯 2024-11-07 18:32:03

这取决于它们需要到达 WAR 中的哪个位置,但通常您可以执行以下操作:

package(:war).include(_(:source, :main, :java, "**/*.html"))

:war 包是 :jar 包的特化,它是:zip 包的专门化,因此您可以使用任何记录的方法< /a> 也适用于 :jar:war 上的 :zip

It depends on where in the WAR they need to go, but generally you can do something like this:

package(:war).include(_(:source, :main, :java, "**/*.html"))

The :war package is a specialization of the :jar package, which is a specialization of the :zip package, so you can use any of the documented methods for :jar or :zip on a :war, too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文