我有四个 Maven 项目:
- 客户端 api jar
- web 服务 war
- ui jar
- web 界面 war
服务 war 需要打包以包含客户端 api jar 以及 javadocs (以便每个版本的服务都与捆绑的客户端 jar 一起分发)和网络文档)。 Web 界面战争将需要 ui jar 和所有依赖项(webstart/applet 部署)。
所以我需要一个第五个项目来完成所有的包装。如何使用 ant 或脚本执行此操作对我来说非常清楚,但在 Maven 中却不清楚。
我尝试了以下操作:
- 将 javadocs 作为 war 打包的一部分包含在内:这需要在项目 2 中执行包之前执行项目 1 中的 javadocs 目标。尚未找到跨不同项目绑定插件/目标的方法。在project2中使用程序集插件也有同样的问题。
- 创建第五个项目并使用程序集插件。仍然存在与以前相同的问题,因为我需要每个子项目的不同部分,所以我不明白如何使用程序集来完成此操作。
这在 Maven 中是不是太难了,我应该放弃吗?或者我看错了,那么我应该怎样看呢?
谢谢!
经过进一步思考,这是部分答案:
- 每个项目都应该构建其所有工件。这是通过将插件配置为根据准备资源和打包阶段运行来完成的。因此,就我而言,我将需要生成的所有内容(jar、javadocs、xsd 文档等)准备为不同的工件,以便单个“包”目标执行创建所有内容。因此,这不是“项目 2 如何迫使项目 1 运行不同的目标”,而是“让项目 1 创建其所有工件作为正常生命周期的一部分)。这似乎简化了事情。
I have four maven project:
- client api jar
- web service war
- ui jar
- web interface war
The service war will need to be packaged to include the client api jar, together with javadocs (so that each version of the service is distributed with a bundled client jar and web documentation). The web interface war will need the ui jar and all the dependencies (webstart/applet deployment).
So I need a 5th project that does all the packaging. How to do this with ant or a script is perfectly clear to me, but not in maven.
I tried the following:
- having the javadocs included as part of the war packaging: this requires the execution of the javadocs goal in project 1 before execution of package in project 2. Haven't found a way to bind plugins/goals across different projects. Using the assembly plugin in project2 had the same problem.
- create a fifth project and use the assembly plugin. Still the same problems as before, with the problem that since I need different pieces from each sub-project I do not understand how this can be done using the assembly.
Is this too hard to do in maven, and should I just give up? Or I am looking at it wrong, in which case, how should I be looking at it?
Thanks!
Upon further reflection, here is a partial answer:
- Each project should build all its artifacts. This is done by having the plugins configured to run as per the prepare-resources and package phases. So, in my case, I prepare all that needs to be generated (jar, javadocs, xsd documentation, ...) as different artifacts so that a single "package" goal execution creates all. So, it's not "how project 2 forces project 1 to run different goals", but it's "make project 1 create all of its artifact as part as the normal lifecycle). This seems to simplify things.
发布评论
评论(2)
我在你的描述中看到的第一件事是你在混合东西。打包客户端api(打包阶段)没问题。但现在您想制作一个包含 JavaDocs 的 client-api.jar 吗?这有点奇怪。为什么不创建两个工件(client-api-1.0.jar 和 client-api-1.0-javadoc.tar.gz )?这两个工件之间的关系是版本号。这可以通过查看 Maven Assembly 插件常见问题解答来解决
您提到的第二件事是“网络界面”,这也可以通过程序集插件来实现(深入研究文档)。也许您可以发布您拥有的 pom,以便我们可以提供更详细的帮助。
顺便说一句:你不需要 ant。 Maven 可以处理这个问题。
The first thing i see in your description you are mixing things. Package the client api (package phase) no problem. But now you would like to make a client-api.jar which includes JavaDocs ? That's a little bit strange. Why not creating two artifacts (client-api-1.0.jar and client-api-1.0-javadoc.tar.gz ) ? The relationship between those two artifacts is the release number. This can be solved by taking a look into the Maven Assembly Plugin FAQ
The second thing you mentioned "web interface" this can be achieved with the assembly plugin as well (Take a deep look into the docs). May be you can post the pom's you have so we can help in a more detailed way.
BTW: You don't need ant for that. Maven can handle that.
您需要创建客户端项目的源 jar并将此源 jar 包含在 war 模块的 javadoc 插件的配置中。各个部分的步骤和配置在 从依赖项源聚合 Javadoc。
对于需要下载的小程序,使用
dependency :copy
在预打包
期间将其复制到 Web 应用程序中的“正确”位置。请参阅用法页面。对于 webstart 应用程序,请查看 将 JNLP 应用程序添加到现有的战争。使用专用模块绝对是创建包含其他模块甚至其他模块的程序集生成的工件的程序集的方法。
我不是 100% 确定,但创建一个
bin
或修改版本(用于捆绑 jar 或 war、 javadoc 等)。然后通过程序集依赖关系组装程序集 在一个专用模块中(解压它们,过滤你想要或不想要的内容,重新打包过滤后的结果)。这需要花一些时间在自定义程序集描述符上但这绝对是可能的。但很难更精确。You'll need to create a source jar of the client project and to include this source jar in the configuration of the javadoc plugin in the war module. The steps and the configuration of the various parts are explained in Aggregating Javadocs from Dependency Sources.
For the applet that needs to be downloadable, use
dependency:copy
to copy it at the "right" place inside your webapp duringpre-package
. See the usage page. For the webstart application, have a look at Add JNLPs apps to an existing WAR.Using a dedicated module is definitely the way to go to create an assembly including artifacts produced by other modules or even assemblies of other modules.
I'm not 100% sure but creating an assembly of assemblies is probably what I would do here. Basically, this means setting up Maven to create an assembly of each module you want to assemble in the final bundle, possibly using the predefined assembly descriptor
bin
or a modified version (to bundle the jar, or war, the javadoc, etc). And then to assemble assemblies via assembly dependencies in an dedicated module (to unpack them, filter what you want or don't want, repack the filtered result). This will require to spend some time on a custom assembly descriptor but it's definitely possible. It's hard to be more precise though.