Tuesday, May 14, 2013

Understanding Archetypes and pom.xml



Folder stucture and pom.xml: are downloaded from maven repository based on the inputs which we have provided (mvn archetype:generate)

archetype:generate
---------------------
1. Archetype: This defines what is the kind of project we need. While running archetype:generate command maven come with huge list of archtypes each points to particular application which you want to  develop. There are archtype for j2ee, spring, hibernate application... etc. Each archtype available in maven repository. If you want to develop simple java web application then you would use java web application archtype.

2. Group ID: package name
3. Artifact ID: Application name
This two identifies what is the output we are generating, says our project generates a jar file. we need to give group id and arctifact id for that jar file, so that artifact is the output of the project if it is web application it would be a WAR, if it is enterprise application it is a EAR. Group Id is the explanatory ID to group all Artifacts says I have big project which has 7 to 8 artifacts so all the arifacts come under common Group Id

4. Version: Default is 1.0-SNAPSHOT, it will be change for every milestone of project.
5. Package: Where we place the source code eg: jar/war/ear.

All the above information present in pom.xml

pom.xml
1. Maven co-ordinates: Identifier of artifact which has groupid, artifactid, version and pkg.
2. Metadata: what the project is, what the version is
3. Build Information: It says the project is jar/war/ear
4. Resources and Dependencies

 ***************************************************************************
 We'll now learn what the build process in Maven consists of, the build phases and we'll run commands to execute some phases.

Maven Build
1.Build life  cycle: every build has a life cycle write code, compile, run test case, pkg it, we install in some repository etc.

2.consists of phases: 2 phase compile and test

3.Default behavior of phases

4.Specify the build phase you need. Previous phases automatically run.

Some Phases
----------------

1. validate: You won't call this explicitly. It checks, is everything in order pom.xml, folder etc.

2.compile: .java to .class before this it run validate phase -> command - mvn compile

3. test: test directory to run test phases -> command -> mvn test

4. package: It execute all the above cases, if all the above 3 test phases run successfully then package happen else error will occur. package might be jar, war or ear. -> command - mvn package

5. Install: Install artifact in local repository/publish your jar in local repository -> command - mvn install

6. deploy: To deploy to remote repository -> command - mvn deploy

No comments:

Post a Comment