What is Maven?. Why it is used for?
Maven is a Java build tool used for web, mobile and desktop application in the development process and it is declarative in the pom.xml. the configuration file contains all the dependencies and scm source.how to know maven version using the command line
use the following code via command line
mvn --version
How do you create a war file using maven?
use the following code via command lineuse install goal to create a war file
mvn clean install
What are the different goals available in a maven project?
There are different predefined available goalsGoal Name | Description |
---|---|
clean | remove all the files generated during the previous run under target folder |
test | running unit and integration tests |
install | compiles and run and generates war file in the target folder |
deploy | the generated war file to the target server. You need to configure server details in pom.xml |
site | Generates artifacts site documentation for maven project |
Explain POM.xml in detail?
pom.xml file is an important component of any maven project. It contains important information about your project and dependencies. POM abbreviated as Project object model which is XML file.- Project detailed information like artifact name and snapshot version dependencies SVN/git repository information
- Profiles, where Development code base has dev profile and production, has a different profile
- Plugin configuration Parent dependencies
How to compile java project using maven.
Maven has a predefined goal called compile which compiles all the java files and generates class files in the target folder
// compile source code
mvn compile
// compile test java files
mvn test
To know Maven direct and indirect dependencies?
Sometimes a developer needs to know project dependencies and transitive dependencies to resolve conflicts with different versions of artifacts.
mvn dependency:tree