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
Maven: Combining multiple module jars into one war file?
提问by daydreamer
I have a project babybird
which has 3 components persistence
, business
and service
我有一个babybird
包含 3 个组件的项目persistence
,business
并且service
in babybird
's pom.xml
I have following
在babybird
的pom.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 web
or similar:
这相当简单。创建另一个名为web
或类似的模块:
<modules>
<module>persistence</module>
<module>business</module>
<module>service</module>
<module>web</module>
</modules>
web
module should depend on all others:
web
模块应该依赖于所有其他模块:
<dependencies>
<dependency>
<groupId>...</groupId>
<artifactId>persistence</artifactId>
</dependency>
...
</dependencies>
and have war
packaging:
并有war
包装:
<packaging>war</packaging>
You'll also need web.xml
in /src/main/webapp/WEB-INF
. That's it.
您还需要web.xml
在/src/main/webapp/WEB-INF
. 而已。