Rikesh Subedi
Rikesh Subedi

Reputation: 1845

combine different maven web-projects into a single project

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?

Upvotes: 2

Views: 5347

Answers (2)

asgoth
asgoth

Reputation: 35829

Let's say you have a multi module project with:

  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 has packaging pom and includes the other 3 modules:

<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 uses the standard jar packaging:

<parent>
   <artifactId>mysite</artifactId>
   <groupId>mysite</groupId>
   <relativePath>../mysite/</relativePath>
</parent>
<groupId>mysite</groupId>
<artifactId>mysite-core</artifactId>

mysite-web is similar:

...
<artifactId>mysite-web</artifactId>

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>

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>

Note: It is best to have a flat project layout, like:

  • root
    • parent pom module
    • java pom module
    • java-1 jar module
    • java-2 jar module
    • web resources jar module
    • war module

instead of a hierarchical layout:

  • root
    • parent pom module
      • java pom module
      • java-1 jar module
      • java-2 jar module
      • web resources jar module
      • war module

I've noticed that tools like Eclipse don't like hierarchical structures (slow or even endless builds).

Upvotes: 4

Alessandro Santini
Alessandro Santini

Reputation: 2003

Use Maven modules. There is extensive documentation here:

http://maven.apache.org/guides/mini/guide-multiple-modules.html

Upvotes: -1

Related Questions