使用额外的非必要文件和批处理文件构建基于非 webapp maven2 的项目
我刚刚开始掌握 maven2 的设置,同时移植我的一个简单项目。 我已经浏览了 包命令行示例在 Sonatype 网站上,但我对如何扩展和更改该项目的打包有点困惑。 我试图找到有关此主题的更多信息,但我认为我要么对问题的思考错误,要么对搜索的措辞错误。
本质上,我想构建一个项目,该项目将是所有依赖项 jar、主 jar 本身、为方便起见启动它的批处理脚本以及应用程序的其他各种文件(如属性文件或其他文件)的 zip。 但是,我不希望将这些全部捆绑到罐子中。 我只想有一个项目的压缩存档版本,其中包含所有 jar 的 lib 目录,根目录包含属性文件和批处理脚本,也许还有子文件夹来保存额外的非必要文件。 有点像:
- sample-proj.zip:
- easy.bat
- props.ini
- 库
- dependent1.jar
- dependent2.jar
- main.jar
- 子目录
- 一些额外文件.txt
使用 maven2 构建这样的项目的正确方法是什么? 我是否需要创建一个构建 zip 并将子项目作为模块包含的父项目? 这只是一个简单的项目,不需要多模块......
I'm just beginning to grasp the setup of maven2 while porting over a simple project of mine. I've ran through the package command line example on the Sonatype web site but I'm a bit confused of how I could expand and change the packaging of this project. I've tried to find more information on this subject but I think I'm either thinking about the problem wrong or phrasing the searches wrong.
Essentially I want to build a project that would be a zip of all the dependency jars, the main jar itself, batch scripts to start it for convenience and maybe other various files for the application (like properties files or something). However, I don't want these all bundled into the jar. I'd like to just have a compressed archive build of the project with a lib directory of all the jars, the root containing properties files and batch scripts and maybe sub folders to hold extra non-essential files. Kind of like:
- sample-proj.zip:
- easy.bat
- props.ini
- lib
- dependent1.jar
- dependent2.jar
- main.jar
- sub_dir
- someextrafile.txt
What's the correct way of building a project like this using maven2? Do I need to make a parent project that builds the zip and includes the sub project as a module? This would be just a simple project that wouldn't need to be multi-module...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以 Matt B 的答案为基础。 以下是如何使用引用的插件的一些示例。 请注意,执行绑定到集成测试阶段,以确保在尝试打包之前已创建 jar。
appassembler-maven-plugin 将生成批处理/shell 文件,下载依赖项(在本例中为 lib 目录),并将所有内容放在 target/appassembler 中
程序集插件可用于将 appassembler 输出打包到 zip 中:
程序集描述符如下所示:
Building on matt b's answer. Here's some examples of how to use the referenced plugins. Note the executions are bound to the integration-test phase to ensure the jar has been created before attempting to package it.
The appassembler-maven-plugin will generate batch/shell files, download the dependencies (in this example to the lib directory), and place all the contents in target/appassembler
The assembly plugin can be used to package the appassembler output into a zip:
And the assembly descriptor looks something like this:
appassembler 插件 完全按照您的描述进行操作:创建 shell 脚本,然后打包增加依赖关系。
但是我不相信它将它们打包到 zip/tar.gz/etc 中(appassembler 只是将它们放入
target/appassembler
下的文件夹结构中。但是,您可以使用 maven-assemble 插件 与 appassembler 配合以打包该输出 - maven- assembly在生成 zip/jar/tar.gz/bzip2/whatever 方面做得非常出色,并且您可以使用 XML 描述符完全控制文件中的内容。The appassembler plugin does exactly what you describe: create shell scripts, and package up the dependencies.
However I don't believe that it packages them up into a zip/tar.gz/etc (appassembler just puts them into a folder structure under
target/appassembler
. But, you can use the maven-assembly plugin in concert with appassembler to just package up that output - maven-assembly does an excellent job of producing a zip/jar/tar.gz/bzip2/whatever, and you can control what goes into the file completely with an XML descriptor.