Maven:如何使用jetty:在多模块Maven项目中运行,无需安装

Maven:如何使用jetty:在多模块Maven项目中运行,无需安装

问题描述:

我是Maven的新手.我有一个多模块maven 2项目,该项目具有以下结构(略有简化):

I'm new to Maven. I have a multi-module maven 2 project that has the following structure (somewhat simplified):

Project (POM packaging)
  |
  +-- Module1 (JAR)
  |     |
  |     +-- src
  |          |
  |          +-- main
  |               |
  |               +-- java
  |               +-- resources
  |
  +-- Module2 (JAR)
  |      |
  |     ...
  |
  +-- Web Module (WAR)
         |
        ...

我已将Web模块配置为包括 Maven Jetty插件. 这对于构建生产工件非常有用.为了进行开发,我发现需要在我更改的任何模块上调用mvn install,然后停止码头并再次调用jetty:run. 如果插件有一种方法可以直接从每个模块的目标目录中选择更改,则将更加高效.根据码头插件文档,似乎有这样的功能,但是看来这仅适用于WAR模块.
对我来说,更重要的是能够对资源文件进行更改,而无需重新启动码头.这是因为大多数资源都是HTML模板文件,并且在开发过程中设计和更新模板而无需重新启动即可查看更改,从而大大提高了生产力.

I've configured the Web Module to include the Maven Jetty plugin. This works great for building the production artifacts. For development, I discovered that I need to call mvn install on any module that I change, followed by stoping jetty and calling jetty:run again.
It would be much more productive if there was a way for the plugin to pick changes directly from each module's target directories. According to the jetty plugin documentation there seems to be such a feature, but it appears this only applies to the WAR module.
Even more important to me is to be able to make changes to resource files, without the need to restart jetty. That's because most of the resources are HTML template files, and it's enormously more productive to design and update the templates during development without needing to restart to see the changes.

那么,有没有办法设置jetty插件的类路径以包括每个JAR模块的目标/类和资源目录,而不是本地存储库中的实际JAR?

So, is there a way to set the classpath of the jetty plugin to include the target/classes and resources directories of each JAR module, instead of the actual JARs in the local repository?

谢谢!
亚尼夫

Thanks!
Yaniv

对于多模块Maven项目,这是不可能的. Maven项目的基本原则是每个项目都应该能够独立存在.这并不妨碍它们一起构建,但是只要满足所有依赖关系,任何一个项目都应该能够自己构建.

This isn't possible with a multi-module Maven project. A cardinal rule of Maven projects is that each project should be able to stand alone. That doesn't preclude them from being built together, but any one project should be able to be built by itself so long as all it's dependencies are satisfied.

在这种情况下,这意味着WAR项目无法查看其他项目是否需要更新,这些其他项目的POM是对构建工件所需要做的明确声明.一旦构建了工件,就将其放入本地存储库中.此时,源文件和工件之间没有关联,因此无法判断哪些源文件将触发WAR依赖的工件的重建.

In this case, it means that the WAR project cannot look out to the other projects to see if they need to be updated, the POM for those other projects are the definitive declaration of what needs to be done to build the artifact. And once the artifact is built, it is put in the local repository. There is no association between the source files and the artifact at that point, so there's no way to tell what source files would trigger a rebuild of the artifact that the WAR depends on.