Purpose
1) Adding set of Jars in each project
2) Creating the right project structure:
3) Building and Deploying the project:
Components
1) A Maven repository is a location where all the project jars, library jars, plugins or any other particular project-related artifacts are stored and can be easily used by Maven.There types are local, central and remote
2) Usually an artifact is a JAR file which gets arrayed to a Maven repository. One or more artifacts a maven build produces such as compiled JAR and a sources JAR.
Each artifact includes a group ID, an artifact ID and a version string.
3)There are two types of Maven Plugins:
- Build plugins – These plugins are executed during the build and are configured in the <build/> element of pom.xml
- Reporting plugins – These plugins are executed during the stage generation and are configured in the <reporting/> element of the pom.xml.
5)The maven’s order of inheritance is
- Parent Pom
- Project Pom
- Settings
- CLI parameters
mvn −version
mvn package
- validate
- compile
- test
- package
- integration-test
- verify
- install
- deploy
18) For POM what are the minimum required elements?
The minimum required elements for POM are project root, modelVersion, groupID, artifactID and version.
19) Explain how you can produce execution debug output or error messages?
To produce execution debug output you could call Maven with X parameter or e parameter.
20) Explain how to run test classes in Maven?
To run test classes in Maven, you need surefire plugin, check and configure your settings in setting.xml and pom.xml for a property named "test."
Apache Maven helps to manage
- Builds
- Documentation
- Reporing
- SCMs
- Releases
- Distribution
Essential elements of MAVEN
- project: Root Element
- modelVersion: subelement
- groupId: id for the project group
- artifact Id: name of the project
- version: version of project
- packaging : war/jar/ear
- dependencies /dependency : third party or witin
- url : url of project
- scope :[compile | provided | runtime |test | system]
- name : name of project
Setting up MAVEN
Maven is a project management and comprehension tool
that provides developers a complete build lifecycle framework.
Default project structure is provided by Maven
Item | Default |
---|---|
source code | ${basedir}/src/main/java |
Resources | ${basedir}/src/main/resources |
Tests | ${basedir}/src/test |
Complied byte code | ${basedir}/target |
distributable JAR | ${basedir}/target/classes |
1.Add environment variable
OS | Output |
---|---|
Windows |
Set the environment variables using system properties.
M2_HOME=C:\Program Files\Apache Software Foundation\apache-maven-3.3.1 M2=%M2_HOME%\bin MAVEN_OPTS=-Xms256m -Xmx512m
|
Linux |
Open command terminal and set environment variables.
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.1 export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m
|
Mac |
Open command terminal and set environment variables.
export M2_HOME=/usr/local/apache-maven/apache-maven-3.3.1
export M2=$M2_HOME/bin
export MAVEN_OPTS=-Xms256m -Xmx512m
|
Add Path
Windows | Append the string ;%M2% to the end of the system variable, Path. |
Linux | export PATH=$M2:$PATH |
Mac | export PATH=$M2:$PATH |
OS | Task | Command |
---|---|---|
Windows | Open Command Console | c:\> mvn --version |
Linux | Open Command Terminal | $ mvn --version |
Mac | Open Terminal | machine:~ joseph$ mvn --version |
- project dependencies
- plugins
- goals
- build profiles
- project version
- developers
- mailing list
Phase | Handles | Description |
---|---|---|
prepare-resources | resource copying | Resource copying can be customized in this phase. |
validate | Validating the information | Validates if the project is correct and if all necessary information is available. |
compile | compilation | Source code compilation is done in this phase. |
Test | Testing | Tests the compiled source code suitable for testing framework. |
package | packaging | This phase creates the JAR/WAR package as mentioned in the packaging in POM.xml. |
install | installation | This phase installs the package in local/remote maven repository. |
Deploy | Deploying | Copies the final package to the remote repository. |
xmlns = "http://maven.apache.org/POM/4.0.0" xmlns:xsi = "http://www.w3.org/ 2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
Plugins Types
Build plugins
Repositary plugin
Maven is actually a plugin execution framework where every task is actually done by plugins. Maven Plugins are generally used to −
- create jar file
- create war file
- compile code files
- unit testing of code
- create project documentation
- create project reports
A plugin generally provides a set of goals, which can be executed using the following syntax −print data on console maven-antrun-plugin
Repositary plugin
RepositoriesLocation where built WAR/EAR/JAR or any other artifact will be stored after code build is successful.false
What is Archetype?
C:\MVN>mvn archetype:generate
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation = "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">4.0.0
- Check-in the code from all project in progress into the SVN (version control system) or source code repository and tag it.
- Download the complete source code from SVN.
- Build the application.
- Store the build output either WAR or EAR file to a common network location.
- Get the file from network and deploy the file to the production site.
- Updated the documentation with date and updated version number of the application.
C:\MVN>mvn archetype:generate
-DgroupId = com.companyname.automobile -DartifactId = trucks -DarchetypeArtifactId = maven-archetype-webapp -DinteractiveMode = false
Maven handles the following activities of a developer
- Build
- Documentation
- Reporting
- Dependencies
- SCMs
- Releases
- Distribution
- Mailing list
No comments:
Post a Comment