Pitch your project

Random text






Blogs

0    
By admin Category Uncategorized, Posted December 23rd, 2015
Introduction to Maven Templating Toolkit

While developing Java projects, Ant was mostly used in declaring the build process, but it was procedural, meaning that you needed to provide information about what to do and when to do through code. You need to provide order, but a build process is an essential part of any development cycle because it helps close the gap between the development, integration, test, and production environments which speeds up the migration of software from one environment to another removing many issues related to compilation, classpath or properties that costs many projects time and money.

Then came along maven, the ultimate build automation tool for java projects, which uses a declarative approach to project build process, where everything is defined in the pom.xml file. What is POM, you ask? Well POM (Project Object Model) is the fundamental unit of work in Maven – It is an XML file that contains information about the project and configuration details used by Maven to build the project, containing default values for most projects.(The POM was renamed from project.xml in Maven 1 to pom.xml in Maven 2, where goals or plugins are now configured.)

Example of POM.xml file

<project>
    <modelversion>4.0.0</modelversion>
    <groupid>com.mycompany.app</groupid>
    <artifactid>my-app</artifactid>
    <version>1</version>
    <packaging>pom</packaging>

    <modules>
        <module>my-module</module>
    </modules>
</project>

Maven project structure

- /my-app
- pom.xml
- /src
  - /main
    - /java
      - /com
        - /mycompany
          - /app
            - App.java
  - /test
    - /java
      - /com
        - /mycompany
          - /app
            - AppTest.java

There are just two subdirectories of this structure: src and target. The only other directories that would be expected here are metadata like CVS or .svn, and any sub projects in a multi project build (each of which would be laid out as above).

The target directory is used to house all output of the build.

The src directory contains all of the source material for building the project, its site and so on. It contains a subdirectory for each type: main for the main build artifact, test for the unit test code and resources, site and so on.

Within artifact producing source directories (i.e. main and test), there is one directory for the language java (under which the normal package hierarchy exists), and one for resources (the structure which is copied to the target classpath given the default resource definition).

Difference between maven and ANT.

Ant Maven
Ant doesn’t has formal conventions , so we need to provide information of the project structure in build.xml file. Maven has a convention to place source code, compiled code etc. So we don’t need to provide information about the project structure in pom.xml file.
Ant is procedural , you need to provide information about what to do and when to do through code. You need to provide order. Maven is declarative , everything you define in the pom.xml file.
There is no life cycle in Ant. There is life cycle in Maven.
It is a tool box. It is a framework.
It is mainly a build tool. It is mainly a project management tool.
The ant scripts are not reusable. The maven plugins are reusable.
It is less preferred than Maven. It is more preferred than Ant.

Maven’s primary goal is to allow a developer to comprehend the complete state of a development effort in the shortest period of time. In order to attain this goal there are several areas of concern that Maven attempts to deal with:

  • Making the build process easy
  • Providing a uniform build system
  • Providing quality project information
  • Providing guidelines for best practices development
  • Allowing transparent migration to new features

In the case of the HHS project, we began my manually creating the files and folder structure that were necessary for the project and later on had to generate a “WEBAPP” maven project, where using command mvn archetype:generate -DgroupId=com.codepamoja.HHS -DartifactId=HHS-DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false which drastically improved deploying to tomcat much easier by running the command mvn clean install, which in turn generates a WAR file (Web Application Archive) file which is used to distribute java classes and web pages(JSPs) and other resources that together constitute a web application which you deploy to Apache Web Server’s Tomcat servlet container.

Posted by Michael Mathenge

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *