0

I have few web projects which share around 95% of the UI. Currently I have set up junctions on my windows machine so when I make a change in the jsp file, all projects get the same update instantly. So I don't have to update every single file.

This approach works but is clumsy as I have to set up Junctions which are pain, and easy to break.

How can I use maven to resolve this issue? Can I just pack up the whole UI (jsp's) into .war and include this in every project? would this work? Or is there any other way?

Thanks

Maciej Cygan
  • 5,351
  • 5
  • 38
  • 72

1 Answers1

1

The maven-war-plugin will let you create a war file with all of your web files in it, and use it as an overlay on dependent projects.

Let's say I have some ui code in a project like this

src
 |-main
    |-webapp
        |-jsp
        |  |-thing1.jsp
        |  |-thing2.jsp
        |-WEB-INF
           |-web.xml

and its pom.xml looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>foo.bar.baz</groupId>
  <artifactId>big-messy-ui</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

After I do a maven install on my UI project, I can include it in applications like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>
  <groupId>foo.bar.baz</groupId>
  <artifactId>some-app</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <dependencies>
    <!-- include ui as an overlay -->
    <dependency>
      <groupId>foo.bar.baz</groupId>
      <artifactId>big-messy-ui</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <type>war</type>
    </dependency>
  </dependencies>

  <build>
    <finalName>SomeApp</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Now the war file for SomeApp will have everything that is included in the local project, plus everything in the messy ui I imported:

SomeApp.war:

jsp
 |-thing1.jsp // from overlay
 |-thing2.jsp // from overlay
 |-plus anything from SomeApp's src/main/webapp/jsp
META-INF
 |-MANIFEST.MF
WEB-INF
 |-classes
 |   |-.class files from SomeApps's src/main/java
 |-web.xml (from SomeApp, the web.xml from the overlay is dropped)
azurefrog
  • 10,785
  • 7
  • 42
  • 56