将不同的maven web项目组合到一个项目中 [英] combine different maven web-projects into a single project

查看:184
本文介绍了将不同的maven web项目组合到一个项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将超过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:


  1. mysite :父pom模块。

  2. mysite-core :一个ja​​va模块

  3. mysite-web :网络资源模块(javascript,html,...)

  4. mysite-webapp :战争模块

  1. mysite: a parent pom module.
  2. mysite-core: a java module
  3. mysite-web: a web resources module (javascript, html, ...)
  4. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆