Maven Interview Questions

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 line
use 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 goals

Goal Name



remove all the files generated during the previous run under target folder


running unit and integration tests


compiles and run and generates war file in the target folder


the generated war file to the target server. You need to configure server details in pom.xml


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  

How to compile and run the test code of the project. 

You can compile the test code using the test goal. if you want to run it, You need maven surefire plugin dependency. You need configuration of test classes and resource files in pom.xml for generation of output

How to skip testing during the maven build process?

 sometimes it is required to skip the test class running. there are many ways to skip running test classes. use -DskipTests or -Dmaven.test.skip=true options to maven command

Similar Posts