简体   繁体   English

从Maven将多模块项目构建到一个war文件中

[英]Building multi-module project from Maven into one war file

My question has been asked before, which I know, but I think that I am trying to do something slightly different, where existing answers are not appropriate. 我以前已经问过我的问题,但我知道,但是我认为我尝试做一些略有不同的事情,而现有的答案是不合适的。

Essentially, I do want to have multiple projects in Eclipse that will be built (preferably) into one final WAR file. 本质上,我确实希望在Eclipse中有多个项目,这些项目将(最好)构建到一个最终的WAR文件中。 Ideally like this: 理想的是这样的:

root - pom.xml
|___ java-app
|___ web-service-v1
|___ web-service-v2
|___ web-service-v3
|___ rest-service
|___ batch-service

Imagine the Java App as the actual application, and each additional component runs as a decoupled view layer for the Java App itself. 想象一下Java App是实际的应用程序,每个附加组件都作为Java App本身的分离视图层运行。 Ultimately, the Java application will be running in a tomcat instance, with the different modules providing their services. 最终,Java应用程序将在tomcat实例中运行,并由不同的模块提供服务。 I would like all the different modules also to run in the same Spring container. 我希望所有不同的模块也可以在同一个Spring容器中运行。

I don't know that running in Maven modules is the best way of doing this, but I would really prefer to have each component in a separate Eclipse project that ultimately get built together. 我不知道在Maven模块中运行是执行此操作的最佳方法,但是我真的希望每个组件都在一个单独的Eclipse项目中,最终将它们组合在一起。

Can anyone provide any suggestions as to how I would use Maven to build this? 谁能提供任何有关我将如何使用Maven构建它的建议?

Just make a separate war module: 只需制作一个单独的战争模块:

root - pom.xml (packaging: pom!!!)
|___ java-app
|___ web-service-v1
..
+--- mod-war (pom.xml)

and put the dependencies of the modules you would like to have added to the war file into the pom and that's it. 然后将您想要添加到war文件中的模块的依赖项放入pom中。

The main Maven idea is that each module must produce a single build artifact (eg a jar or a war file). Maven的主要思想是每个模块必须产生一个单独的构建工件(例如jar或war文件)。 The parent pom is usually responsible for global configuration and dependency management and also for a proper module orchestration. 父pom通常负责全局配置和依赖性管理,还负责适当的模块编排。 If your final result need to be a WAR file, then last module in the list will be the web application. 如果最终结果需要是WAR文件,则列表中的最后一个模块将是Web应用程序。 The other modules could supply classes that war file depend on. 其他模块可以提供war文件所依赖的类。

There are more complicated build structures, but above one should be sufficient for you. 有更复杂的构建结构,但以上一种对您而言已足够。

This is somewhat dated, but hope this additional info helps someone. 这有些过时了,但希望此附加信息对某人有所帮助。

@Mouscellaneous An example of keeping Spring configs in each module and referencing them from the web.xml can be found here in the Sonatype book . @Mouscellaneous一个在每个模块中保留Spring配置并从web.xml引用它们的示例可以在Sonatype书中找到 I guess this is what you are looking for. 我想这就是您要寻找的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM