Introduction to Maven and Spring

Hi,nice to see you again and today let us have a look about Maven.

Maven is a build tool that can be used with Java. There are several build tools for Java, Ant, Maven, Gradle are some of them.

Ant vs Maven

  • Both are two popular bulid tools used by Java community.
  • Ant can be considered as the foundation for Maven.
  • Main benefit of Ant is its flexibillity.Ant doesnot impose any conventions or project stuctures, which means Ant reqiures developers to write all the commands by themselves.But Maven relies on conventions and provides predefined commands.
  • Maven is built on the concept of "Convention over configuration".

Convention over Configuration

Maven uses Convention over Configuration which means developers are not required to create build process themselves.Maven provides sensible default behavior for projects. 

Maven contain pre-configured project presets called Archetypes.

Phases of a project

-clean: Cleanup the artifacts generated by previous builds.
-compile: Compile the source code
-package: Create a distributable bundle
-install: Copy the package into the local repository
-deploy: Copy the final package to the release environment or publish to a remote repository
-test: Execute the test cases 

Archetypes

A templating toolkit.
Can define custom Archetypes according to our own requirements.

Maven provides several archetype artifacts,

maven-archetype-archetype      An archetype to generate a sample archetype project.
maven-archetype-plugin           An archetype to generate a simple maven plugin.
maven-archetype-quickstart     An archetype to generate a sample maven plugin.
maven-archetype-webapp         An archetype to generate a sample maven webapp project. 

POM (Project Object Model)

POM  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. When executing  a task or goal, Maven looks for the POM inside the current directory. It reads the POM inorder to get the needed configuration information, to execute the goal.

Spring Framework

A Java platform that provides comprehensive infrastructure support for developing Java application.
It is mostly famous for Dependency Injection with the favour of Inversion of Control (IoC).



Inversion of Control

It is a principle in software engineering which control objects or portions of program transfered to a container.

Advantages of this architecture,

  • Decoupling the execution of a task from its implementation.
  • Making it easier to switch between different implementations.
  • Great ease in testing a program by isolating a component.
Dependency Injection

Dependency Injection is a pattern which implements IoC.

Now let me explain this concept with an example,

Here is how you would create an object dependency in traditional programming,
Now let us implement the above implementation using IoC



That's it for today,

Hope to see you with another blog post,
Till then,
Good bye













Comments