Maven Introduction and Architecture

 Maven:-Maven is a build automation tool which generates the build for you.

Build:-Suppose we want to create a java project to connect java application with RDBMS(like oracle). For that  we have to download the Driver(Jar file or OJBDC Jar) from the internet. And after that we have to add this Driver or Jar file into the build path of the application. To do this right click on the project(If you are using Eclipse IDE) >Click on build path>Click on Add External Archives>Choose the jar file >Click on finish . To add the jar file or any dependency we have to download the dependency from the internet.

In Maven we don't do such stuff. In maven all the technologies or jars will be available in the form of dependencies. Some Maven repository is available over the internet on maven centralized repository in the market. What they did some genius guys created a centralized repository somewhere let us assume it is in US. And we are in India and we are creating the project so the maven server will send the request  to the maven's centralized server and will return with response in the form of dependencies.

It works in the form of client server model.

Any dependencies we have 3 sections or phases.

1.Articat Id.

2.Group Id.

3.Version No.

Vendors will do the entry for the dependency name,version no,group id and artifact id  etc in the centralized repository.

Maven Centralized Repository:-is nothing but collections of the all the dependencies. And all the open source technologies will be available here. And location for that will be the maven centralized location. Inside maven centralized repository you will get all the versions (If vendor is updating the version time to time )that are available.

We will send the request in the form of dependencies and we will get jar file in our project in the form of response . What maven will do maven will store the jars in .m2 folder in your machine(C:\Users\username\.m2\repository). This is known as the local repository. Our Eclipse will use the jars from the .m2 repository or local repository.

Install Maven In Windows

To install maven in your machine in case of windows os  click here.

Maven Life Cycle

There are three major life cycles of the maven 

1.Maven compile:-It means whatever the classes are available compile it as a single unit . And this compilation will happen by using maven compiler plugin.

2.Maven Test:- In this phase your test cases will run. The surefire plugin is responsible for runing the test cases .

3.Maven Resource or Jar:- After the compilation and test cases done maven have to create the resources(jars or wars or ears). And this happens with the help of Maven Resources Plugin.


Setup your maven project in eclipse

When you will setup you maven project with eclipse for that you have to give three things.

1.Group Id:-This is same as the package name of the project.

2.Artifact Id:-This is same as the project name .

3.Version No:-This is the version number of the project.

When you will create a java project using maven you will get a file with name pom.xml. This pom.xml file is the heart of the maven. In this file you will entry the name of the dependencies whatever you want inside your project.

If we are updating any jar using maven from x.x.x version to x.x.x version so maven will automatically delete it and update it in your project you not need to worry about that .

To execute the life cycles:-

mvn clean install

It will create the jar file or build for our project.

To execute test cases:-

mvn test

It will only execute your test cases.

To Skip test cases:-

mvn package -DskipTests

in this case build will create but test case will not compile and executes.

One more way to skip your test cases inside your test cases inside your <properties></properties> section add <maven.test.skip>true</maven.test.skip>. If it is true than it means all the test cases will be ignore . If it is false than all the test cases will be considered.  And use the command mvn package -Dmaven.test.skip=true.

Note:-It is not a best practice to skip the test cases. It is always mandatory to run the unit test cases with the build.



Comments