将不同的maven web项目组合到一个项目中 [英] combine different maven web-projects into a single project
问题描述
我希望将超过3个maven项目(基于HTML,javascript和CSS)合并为一个。我的主项目使用其他项目的依赖项。那么,如何构建单个项目而不更改这些依赖项?
I want to combine more than 3 maven projects (HTML, javascript and CSS based) into a single one. My main project uses dependencies from other projects. So, how can I build a single project without changing those dependencies?
推荐答案
假设您有一个多模块项目:
Let's say you have a multi module project with:
-
mysite
:父pom模块。 -
mysite-core
:一个java模块 -
mysite-web
:网络资源模块(javascript,html,...) -
mysite-webapp
:战争模块
mysite
: a parent pom module.mysite-core
: a java modulemysite-web
: a web resources module (javascript, html, ...)mysite-webapp
: a war module
mysite
有打包pom
并包括其他3 模块
:
<groupId>mysite</groupId>
<artifactId>mysite</artifactId>
<packaging>pom</packaging>
<modules>
<module>../mysite-core</module>
<module>../mysite-web</module>
<module>../mysite-webapp</module>
</modules>
mysite-core
使用标准 jar包装
:
<parent>
<artifactId>mysite</artifactId>
<groupId>mysite</groupId>
<relativePath>../mysite/</relativePath>
</parent>
<groupId>mysite</groupId>
<artifactId>mysite-core</artifactId>
mysite-web
类似:
...
<artifactId>mysite-web</artifactId>
mysite-webapp
包括java和Web资源模块作为依赖项:
mysite-webapp
includes the java and the web resources module as a dependency:
...
<artifactId>mysite-webapp</artifactId>
<packaging>war</packaging>
<dependency>
<groupId>mysite</groupId>
<artifactId>mysite-core</artifactId>
</dependency>
<dependency>
<groupId>mysite</groupId>
<artifactId>mysite-web</artifactId>
</dependency>
使用叠加属性> maven-war-plugin ,你将资源添加到战争中:
With the overlays property from the maven-war-plugin, you add the resources to the war:
<overlays>
<overlay>
<groupId>mysite</groupId>
<artifactId>mysite-web</artifactId>
<type>jar</type>
</overlay>
</overlays>
注意:最好有一个平面项目布局,如:
- root
- 父pom模块
- java pom模块
- java-1 jar模块
- java-2 jar模块
- web资源jar模块
- war模块
- root
- parent pom module
- java pom module
- java-1 jar module
- java-2 jar module
- web resources jar module
- war module
而不是分层布局:
- root
- 父pom模块
- java pom module
- java-1 jar模块
- java-2 jar模块
- web资源jar模块
- 战争模块
- root
- parent pom module
- java pom module
- java-1 jar module
- java-2 jar module
- web resources jar module
- war module
我注意到像Eclipse这样的工具不喜欢层次结构(缓慢甚至无限的构建)。
I've noticed that tools like Eclipse don't like hierarchical structures (slow or even endless builds).
这篇关于将不同的maven web项目组合到一个项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- parent pom module
- 父pom模块