POKE ME for any consultancy

Tuesday, December 22, 2015

Difference between Ant and Maven

Ant and Maven are different building tools in Java. Both the tools are considered good but with slight differences.


ANT full form is Another Needed Tool. Ant is a build tool that is java based. A build tool performs the following tasks:


  • Compiling java code into byte code
  • Placing this byte code in a package
  • Deployment to production systems
  • Document creation and release notes preparation.

Before start using ANT, we should be clear about the project name and the .java files and most importantly, the path where the .class files are to be placed.

How to use Maven
Refer: http://www.javatpoint.com/maven-repository and http://mvnrepository.com/
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html

  • Repeatable builds: if you can build the project, your colleagues will always be able to on their machines. It'll also be repeatable on the build server.
  • Standardization of the build system: new developers who understad Maven will instantly know how to build, release, test etc, removing a lot of learning overhead.
  • Focus on automation: Maven puts you in a mindset of automating processes around your software development.
  • Convention over configuration: no setup or minimal configuration required to build artifacts.
  • Dependency management: Maven will resolve and manage your dependencies for you.
  • Testing: the ability to run tests and integration tests as part of your project life cycle.
  • Plugins: there are thousands of plugins to carry out various tasks. These are simply configured in just by adding a reference into the POM.



The great advantage of using Maven is its repository infrastructure. This promotes standard protocols for the sharing of 3rd party libraries and enables teams to collaborate more effectively without being forced to check everything into the same source code repository (Modular builds).
Repository managers are freely available and I'd recommend installing one of the following:
  • Nexus
  • Artifactory
  • Archiva

Maven pom.xml file:

POM is an acronym for Project Object Model. The pom.xml file contains information of project and configuration information for the maven to build the project such as dependencies, build directory, source directory, test source directory, plugin, goals etc.


Element
Description
projectIt is the root element of pom.xml file.
modelVersionIt is the sub element of project. It specifies the modelVersion. It should be set to 4.0.0.
groupIdIt is the sub element of project. It specifies the id for the project group.
artifactIdIt is the sub element of project. It specifies the id for the artifact (project). An artifact is something that is either produced or used by a project. Examples of artifacts produced by Maven for a project include: JARs, source and binary distributions, and WARs.
versionIt is the sub element of project. It specifies the version of the artifact under given group.

Software Configuration Management Best Practices


  • SCM Best Practices are designed and implemented to ensure software quality, integrity and reproducibility.
  • Properly Supporting Distributive Development Environments.
  • Customize SCM to Support all SDLC Methodologies.
  • Create Auditable Processes.
  • Build Early and Build Often.
  • Fully Automate the Build Process
  • Continuous Integration builds.
  • Creating a repeatable build process
  • Using a secure and dedicated build server
  • Require all necessary files be checked-in prior to the build
  • Label the source code in each build with a unique identifier.
  • Reporting tool to be integrated with Build tools/Source code tools
  • Create a build manifest of the build artifacts.
  • Create and keep your build logs
  • Send build status emails
  • Track release baselines of your software build

Saturday, December 19, 2015

ANT Build file

<?xml version="1.0"?>
<project name="AmitAnand" default="jar" basedir=".">
<property name="src.dir" location="src" />
<property name="build.dir" location="D:\build" />
<property name="project.name" value="AmitAnand" />
<target name="clean">
<delete dir="${build.dir}" />
</target>
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${build.dir}/classes" />
</target>
<target name="compile" depends="clean,makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}/classes"/>
</target>
<target name="jar" depends="compile">
<jar destfile="${build.dir}/jars/${project.name}.jar" basedir="${build.dir}/classes" />
</target>
</project>