Maven: How to use jetty:run in a multi-module Maven project, without needing to install

故事扮演 提交于 2019-11-30 04:39:43

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.

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.

In Eclipse, you can use "Run Jetty" plugin to achieve this.
In IDEA's Run Configuration, there is an option 'Resolve Workspace artifacts', check it.

If you use M2Eclipse (Eclipse plug-in for a close integration of Maven within Eclipse), you can run your jetty:run goal in the web module and other dependencies will be taken into account from your workspace, even if they are not at all available in your local repository.

There is just an option in your run to tell Maven to resolve your modules in the workspace itself (by default, it would just fetch what is deployed in the local repository).

Unfortunately, I cannot have the same behaviour in IDEA and I have to run an install before running the jetty:run on the web module.

tkruse

Based on this answer:Best practice wrt. `mvn install`, multi-module projects, and running one submodule a workaround around Mavens horrible restrictions and reactor limitations is to define the plugin in the parent pom with skip true, and then reenable it in the respective submodule using skip false.

I solved by using a maven launcher and configuring Resolve Workspace artifacts, that is not checked by default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!