panemu

development-tool

Maven Multimodule Project and Nexus

Written by - March 13, 2012

After successfully install Nexus and configure Maven to refer to Nexus, I was tempted to apply that technologies to Tiwul. Tiwul is Java framework created by Panemu. It is ready for 3-tiers architecture and client-server. It uses Hibernate, Spring and Openswing (commonos). Although it uses Openswing, Tiwul front end doesn’t have to be Java Swing. It compatible with web and mobile front-end.

Tiwul consists of 2 modules, tiwul-common and tiwul-core. Tiwul-common will be used both by client and server sides of the application that based on Tiwul framework. Tiwul-core is only used by server side application. That’s why, I configure Tiwul project using Maven’s multimodule skeleton as follow:

In eclipse package explorer image above, there are 3 projects, tiwul, tiwul-common and tiwul-core. Tiwul is the parent of tiwul-common and tiwul-core. It doesn’t have source folder, only pom.xml and its module folders. The pom of tiwul project is below:

<?xml version="1.0" encoding="UTF-8"?>
<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>com.panemu.tiwul</groupId>
     <artifactId>tiwul-parent</artifactId>
     <version>1.0-FINAL</version>
     <packaging>pom</packaging>
     <name>tiwul</name>
     <url>http://www.panemu.com</url>
     <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>

     <dependencies>
          <dependency>
               <groupId>junit</groupId>
               <artifactId>junit</artifactId>
               <version>4.10</version>
               <scope>test</scope>
          </dependency>
     </dependencies>
     <modules>
          <module>tiwul-common</module>
          <module>tiwul-core</module>
     </modules>
</project>

Take alook at groupId, artifactId and version. These attributes will be used in tiwul-common and tiwul-core. Alse packaging type should be pom instead of jar. And See in modules node, there are tiwul-common and tiwul-core in it. Let’s check tiwul-common pom.xml file:

<?xml version="1.0"?>
<project
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
     xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <modelVersion>4.0.0</modelVersion>
     <parent>
          <groupId>com.panemu.tiwul</groupId>
          <artifactId>tiwul-parent</artifactId>
          <version>1.0-FINAL</version>
     </parent>
     <groupId>com.panemu.tiwul</groupId>
     <artifactId>tiwul-common</artifactId>
     <name>tiwul-common</name>
     <url>http://www.panemu.com</url>
     <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
     <dependencies>
          <dependency>
               <groupId>org.openswing</groupId>
               <artifactId>commonos</artifactId>
               <version>2.4.5</version>
          </dependency>
          <dependency>
               <groupId>org.apache.commons</groupId>
               <artifactId>commons-lang3</artifactId>
               <version>3.1</version>
          </dependency>
          <dependency>
               <groupId>org.hibernate</groupId>
               <artifactId>hibernate-core</artifactId>
               <version>4.1.1.Final</version>
          </dependency>
     </dependencies>
</project>

In parent node, it’s defined that its parent project is tiwul-parent. Now let’s see tiwul-core pom.xml:

<?xml version="1.0"?>
<project
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
     xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <modelVersion>4.0.0</modelVersion>
     <parent>
          <groupId>com.panemu.tiwul</groupId>
          <artifactId>tiwul-parent</artifactId>
          <version>1.0-FINAL</version>
     </parent>
     <groupId>com.panemu.tiwul</groupId>
     <artifactId>tiwul-core</artifactId>
     <name>tiwul-core</name>
     <url>http://www.panemu.com</url>
     <properties>
          <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
     <dependencies>
          <dependency>
               <groupId>com.panemu.tiwul</groupId>
               <artifactId>tiwul-common</artifactId>
               <version>1.0-FINAL</version>
          </dependency>
          <dependency>
               <groupId>log4j</groupId>
               <artifactId>log4j</artifactId>
               <version>1.2.16</version>
          </dependency>
     </dependencies>
</project>

Same with tiwul-common, the parent of tiwul-core is tiwul-parent. That pom.xml file also defined that it is dependent to tiwul-common project.

Now it is time to compile. Of course tiwul-common and tiwul-core have classes in it but I will not explain about it. I executed mvn compile then mvn install. Next I checked my local maven repository. I saw this:

Great. That folders contain jar and pom files generated by mvn install. Now time to upload them to Nexus so my peer programmer can use them.

I put Tiwul framework artifacts in 3rd party repository in Nexus. First I uploaded tiwul-parent pom file. After I selected 3rd party repository, I went to Artifact Upload tab, and selected GAV definition to From POM. Next I looked for tiwul-parent-1.0-FINAL.pom and clicked Upload Arficact(s) button in the bottom of the page.

To upload tiwul-common artifacts, select the corresponding pom file, then jar file to upload. In regards with the jar file, I left Classifier information blank.

Don’t forget to click Add Artifact button, before Upload Artifact(s) button. I did similar steps to upload tiwul-core artifacts. To ensure the upload was okay I went to Browse Storage tab and found below:

Everything seems good. I checked tiwul-common-1.0-FINAL.pom and found its contents was the same with tiwul-common’s pom.xml file I had created in Eclipse.

Next I compiled my application that based on tiwul-framework. Of course I deleted /home/anggit/.m2/repository/com/panemu/tiwul folder so maven will download tiwul artifacts from Nexus.

anggit@anggit:~/workspaces/tw3tiers/example$ mvn compile
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
//I omit some lines here
Downloading: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-common/1.0-FINAL/tiwul-common-1.0-FINAL.pom
Downloaded: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-common/1.0-FINAL/tiwul-common-1.0-FINAL.pom (2 KB at 3.2 KB/sec)
Downloading: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-parent/1.0-FINAL/tiwul-parent-1.0-FINAL.pom
Downloaded: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-parent/1.0-FINAL/tiwul-parent-1.0-FINAL.pom (840 B at 5.2 KB/sec)
Downloading: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-common/1.0-FINAL/tiwul-common-1.0-FINAL.jar
Downloaded: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-common/1.0-FINAL/tiwul-common-1.0-FINAL.jar (7 KB at 28.2 KB/sec)
[INFO]
//I omit some lines here
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building tw3tiers-core 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-core/1.0-FINAL/tiwul-core-1.0-FINAL.pom
Downloaded: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-core/1.0-FINAL/tiwul-core-1.0-FINAL.pom (935 B at 4.1 KB/sec)
Downloading: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-core/1.0-FINAL/tiwul-core-1.0-FINAL.jar
Downloaded: http://10.1.1.1:9090/nexus/content/groups/public/com/panemu/tiwul/tiwul-core/1.0-FINAL/tiwul-core-1.0-FINAL.jar (16 KB at 41.9 KB/sec)
[INFO]
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ tw3tiers-core ---
//I omit some lines here
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] tw3tiers .......................................... SUCCESS [0.002s]
[INFO] tw3tiers-common ................................... SUCCESS [2.035s]
[INFO] tw3tiers-core ..................................... SUCCESS [0.767s]
[INFO] tw3tiers-ui ....................................... SUCCESS [0.032s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.000s
[INFO] Finished at: Tue Mar 13 18:03:33 WIT 2012
[INFO] Final Memory: 6M/105M
[INFO] ------------------------------------------------------------------------

The build was succeeded. I can assure that tiwul framework artifacts are available for my peer programmers here in Panemu. To include tiwul-common dependecy, add below code in pom.xml file:

<dependency>
  <groupId>com.panemu.tiwul</groupId>
  <artifactId>tiwul-common</artifactId>
  <version>1.0-FINAL</version>
</dependency>

To include tiwul-core:

<dependency>
  <groupId>com.panemu.tiwul</groupId>
  <artifactId>tiwul-core</artifactId>
  <version>1.0-FINAL</version>
</dependency>
One Response to “ Maven Multimodule Project and Nexus ”
  1. jika lebih banyak pekerjaan kemudian di tulis dalam artikel mungkin akan lebih berguna. karena selain berbagi informasi dan pengalaman juga akan membuta sang penulis lebih mengerti dan memahami. sekaligus untuk menunjukkan bahwa web ini produktif. terimakasih.

    RESPOND FROM artyush - July 16, 2012

Jogjakarta

Telp +62 274 441100