Tuesday, January 9, 2018

Maven Dependency to WAR module

So today, I had to create a new project, which was needed to have a dependency on another internal WAR module. 

The way to do that, is through the WAR module itself.

In the build tag, inside my WAR pom, under plugins I added:

<plugin>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.1-beta-1</version>
   <configuration>
       <attachClasses>true</attachClasses>
   </configuration>
 </plugin>

When deploying your WAR module, the above plugin creates a JAR file with all the classes of your project (along with your WAR). This JAR will be accessible to your new project. In my case, I am deploying in an internal repository server (Apache Archiva). Bellow you can see the contents of my module directory inside Apache Archiva after deploying.

 
WAR module - Apache Archiva directory
WAR module - Apache Archiva directory


In the POM of my new project under the dependencies tag, I added the dependency to my WAR module as seen bellow:

<dependency>
   <groupId>${project.groupId}</groupId>
   <artifactId>e-receipt-api</artifactId>
   <version>1.2</version>
   <classifier>classes</classifier>
 </dependency>

The above code snippet resulted to including the produced JAR file with its classes.

No comments:

Post a Comment