Wednesday, 15 June 2016

Liferay Maven Introduction & Install Maven

Q-What is maven?
ans-"maven is a softwae management and comprehension tool based on the concept of project object model.
Maven do many things for us like resolving dependencies, create project structure, build  a project, creating war/jar etc. By using Maven you can also create portlet, theme, services without any need of sdk. - 

(pom) which can manage project build , reporting and  documentation from centre piece of information."

All build system are essentials the same
there are some step for build projet
1-compile source code.
2-copy resource
3-compile and run test.
4-packge project.
5-deploy project
6-clean up code.

Development of maven wanted:-
Advantege of maven:- maven wanted standard way to build the project they wanted clean definition what the project consist of easy way to publish project information and way to share jar across several the project.
they wanted easy way to build the project and share your project with the colleagues or with the client
so they come up with the tool which is called maven.. which is for building and managing  any java project
maven is intended to make day to day java developer work easier

POM(project object model)
Maven uses the concept of pom..
Q-what is pom?
ans- pom is fundamental unit of work in maven you can say.
"pom is xml file that contain information about the project and configuration details used by maven
to build the project "
note-xml file contail some information
1-describe a project
2- this information contain name, version and artifact, source code location,Dependences of project
3-it also retail the plugin information and profile.
4-it uses xml by default
5- but not the way ant uses xml.

MAVEN Advantag and objective:-

1:-Making the build process easy.
2-provide the uniform a information
3:-provide quality project information
4:-provide guildlines for best practice evelopment
5:-allowing transprant migration for a new feature.

Create first maven project simple

step1-first set class path  with maven
step2-copy that maven project path and pased on command line.
step3-mvn archetype: generate  (this command is used for generate  project from existeing template ) maven project( this command will  help you to create a perfect diretory structure for you)
( when you entre for this command we need internate for download plugin)
note :- generally what happend is  if yu are not using maven than you need to make project structural  by your self


How to create maven project with eclipse:-
ans:-
step:-goto file-new- choose project-search maven-select maven project-next-next-we need to give group id, artifact id,version,package  and leave everything is default
and finish
after  eclipse it will create maven project for us
How maven work internally? 
1--suppose you need any dependencies jar file maven it provide automatically download required  dependencies for that we need to dependency on jar.

example:-if you want unite testing with maven project for that we need to make one java class
inside java class we take one simple method test and write     some dummy code and let say we are returing test

2- we need to right click on test class -goto new-select unit testing we need to give junit test case class name testApp and -finish-ok
3--testApps class you will sea some some error so it required jar file so here maven allow dependencies pom.xml file so that dependenies automatically downloaded jar

for that we need to go pom.xml and add dependencies indise dependencies we need to add dependencies for jnuit project equired junit jar file to compile  maven has online repository from where it can download all the dependencies so just goto google and type maven junit dependencies copy and pased inside dependences after all junit error wiil be remove.

How to install Maven on Windows:-

1. JDK and JAVA_HOME

Make sure JDK is installed, and “JAVA_HOME” variable is added as Windows environment variable.
  • For installing Maven first we need to download maven from here and extract in C drive .

install-maven-on-windows-1

2. Download Apache Maven

Visit Maven official website, download the Maven zip file, for example : apache-maven-3.2.2-bin.zip. Unzip it to the folder you want to install Maven.
Assume you unzip to this folder – C:\Program Files\Apache\maven

3. Add M2_HOME and MAVEN_HOME

Add both M2_HOME and MAVEN_HOME variables in the Windows environment, and point it to your Maven folder.

install-maven-on-windows-3

4. Add To PATH

Update PATH variable, append Maven bin folder – %M2_HOME%\bin, so that you can run the Maven’s command everywhere.

install-maven-on-windows-4

5. Verification

Done, to verify it, run mvn –version in the command prompt.
C:\Users\mkyong>mvn -version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T21:51:42+08:00)
Maven home: C:\Program Files\Apache\maven
Java version: 1.7.0_65, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.7.0_65\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "windows"
C:\Users\mkyong>
If you see a similar message, means the Apache Maven is installed successfully on Windows.

Maven Eclipse plugin installation step by step:
  1. Open Eclipse IDE
  2. Click Help -> Install New Software...
  3. Click Add button at top right corner
  4. Now click OK
After that installation would be started.
Another way to install Maven plug-in for Eclipse:
  1. Open Eclipse
  2. Go to Help -> Eclipse Marketplace
  3. Search by Maven
  4. Click "Install" button at "Maven Integration for Eclipse" section
  5. Follow the instruction step by step
After successful installation do the followings in Eclipse:
  1. Go to Window --> Preferences
  2. Observe, Maven is enlisted at left panel
Finally,

  1. Click on an existing project
  2. Select Configure -> Convert to Maven Project