java Maven:将多个模块 jar 组合成一个战争文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14467325/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 16:23:24  来源:igfitidea点击:

Maven: Combining multiple module jars into one war file?

javamaven

提问by daydreamer

I have a project babybirdwhich has 3 components persistence, businessand service

我有一个babybird包含 3 个组件的项目persistencebusiness并且service

in babybird's pom.xmlI have following

babybirdpom.xml我有以下

   <modules>
        <module>persistence</module>
        <module>business</module>
        <module>service</module>
    </modules>

when I run mvn clean install, I see

当我跑步时mvn clean install,我看到

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] babybird  ......................................... SUCCESS [2.801s]
[INFO] persistence ....................................... SUCCESS [3.321s]
[INFO] business .......................................... SUCCESS [0.832s]
[INFO] service ........................................... SUCCESS [0.694s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.168s
[INFO] Finished at: Tue Jan 22 12:09:48 PST 2013
[INFO] Final Memory: 18M/50M
[INFO] ------------------------------------------------------------------------

and each one of these modules generate a jar file.

并且这些模块中的每一个都生成一个 jar 文件。

Question: How can I combine them into one babybird.war?
I am new to Maven and do not know what to look for to accomplish this task, please provide the pointers

问题:如何将它们合二为一babybird.war
我是 Maven 新手,不知道要寻找什么来完成此任务,请提供指点

回答by Tomasz Nurkiewicz

That's fairly simple. Create another module named webor similar:

这相当简单。创建另一个名为web或类似的模块:

<modules>
    <module>persistence</module>
    <module>business</module>
    <module>service</module>
    <module>web</module>
</modules>

webmodule should depend on all others:

web模块应该依赖于所有其他模块:

<dependencies>
    <dependency>
        <groupId>...</groupId>
        <artifactId>persistence</artifactId>
    </dependency>
    ...
</dependencies>

and have warpackaging:

并有war包装:

<packaging>war</packaging>

You'll also need web.xmlin /src/main/webapp/WEB-INF. That's it.

您还需要web.xml/src/main/webapp/WEB-INF. 而已。