Maven Interview Questions and Answers

Q1. Breifly Explain  What isMaven?
Maven is a build automation tool or a project management tool. With Maven we can import all libraries and can also create project structures. In Maven we have many inbuilt templates. These templates are called archetypes. A Maven is basically a tool used to compile our applications. It helps to develop and managing project structure or applications like deployment, clean, packaging, jar and many more features for the Java-based project.
In another word, it is a Java tool. If you want to create a sample project or skeleton project you can use Maven. It is an automated build tool. The Maven focused on simplicity that it generates intelligent starters and assumes intelligence defaults. It also covers build-oriented phases in Application Lifecycle Management i.e. testing, deployment, builds management, and release versioning.

Q2. What is the use of  Maven?

  • It helps to setup project very quickly and it avoids complicated build files like build.xml. Maven required files like POM.xml; it serves the purpose for Maven only. POM.xml is a collection of dependencies of your Java Project which one can specify to Maven and then Maven will download all of them from the internet and then store it to some repository i.e. local repository, central repository, and remote repository.
  • It helps to not bundle all the jars in your package i.e. in your War file or Ear file because all of them are going store in the repository and wherever you install this application that repository will be used for any dependencies look up. So, your Jar file, War file or Ear file or your bundle deployment will be very light.

Q3. What are Maven’s main objectives?

  • It helps to make project build easy to work for the users.
  • It easily helps in to migrate from one feature to another or one folder to another.
  • It helps in the new development with proper series of guidelines.
  • It creates a flexible working system for the users. So that you can work uniformly and orderly.

Q4. List the Build phases in Maven.
There are 6 build phases.

  1. Validate.
  2. Compile.
  3. Test.
  4. Package.
  5. Install.
  6. Deploy.

Q5. What is maven repository central.
It is the Maven established repository. For example, your POM specify the dependencies and it is not available in the configured local and the remote repository then maven looks for the resource in Maven Central. Maven provides most of the generic dependency resources at this remote location.

Q6. What are the advantages of Maven over Ant?

  • Maven uses Convention whereas ant uses Configuration. In Maven, convention means a standard layout suggested by Maven. If you want a skeleton project of sample Java application, so Maven is going to give you one set of folders and configurations for that Java applications whereas in the case of Ant you need to have lots of configurations.
  • Maven supports project modularization.
  • Maven also supports dependency management and migration.

Q7. Why Maven is used?
• Create a jar file
• Create war file
• Compile code
• Unit testing of code
• Documenting projects
• Reporting

Q8. What is  MOJO?
Maven plain Old Java Object. Each mojo is an executable goal in Maven.

Q9. What is Maven artifact.
An artifact is a JAR, that gets deployed to a Maven repository.
Each artifact has a group ID , an artifact ID (artifact name) and a version string.

Q10. How do you rename a maven project?
1. Rename the project using Eclipse or other IDE.
2. Update the artifactId in your pom.xml

Q11. What are the minimum requirements for a POM?
The minimum requirement for a POM are the following,

  • project root
  • modelVersion
  • groupId
  • artifactId
  • version
  • Test directory is src/main/test that has all the unit testing codes.

Q12.  Explain dependency:copy-dependencies goal.
This goal when executed copies all the project’s dependencies along with the transitive dependencies to the specified folder.

Q13. How many project types available in Maven to choose from?
There is more than thousand Java project as there are templates, skeleton provided to you by Maven so that you do not have to remember a basic configuration detail or a basic setup of that particular type of project which Maven is going to give it to you. It includes examples like basic Java project, Spring Project, Spring MVC, Spring Web Flow, and Spring Boot.

Q14.What is a goal in Maven terminology?
The goals mentioned here in the Maven suggests the managing and building process requires creating a project. There is no limitation to follow the goals in Maven; it can build as many phases as it wants with zero boundations. You directly achieve your goal without any kind of outside intervention.

Q15. List the types of maven repository.
types of maven repository

  • local.
  • central.
  • and remote.

 Q16. Can we use different name for POM.xml?
Yes. You could mention file name using the -f option.
mvn -f parent-pom.xml

Q17. What is the method and installing process of Maven?
Download Maven from:
https://maven.apache.org./download.html
Choose the .zip format.
Extract Maven to:
/usr/local/maven – Unix / Linux
C:Program Filesmaven – Windows

Q18. Explain the highlevel directory structure of a maven project.
target folder holds the compiled unit of code as part of the build process.
Source folder usually src/main/java holds java source codes.
Test directory is src/main/test that has all the unit testing codes.

Q19. What jar:jar goal does?
It creates the jar files from the target/classes directory without recompiling any source classes.

Q20. How do I skip the tests?
Include the parameter -Dmaven.test.skip=true or -DskipTests=true in the command line.

Q21. How can I run a single unit test?
Use the parameter -Dtest=MyTestClassName at the command line.

Q22. Difference between compile and install.
Compiler compiles the source code of the project whereas Install installs the package into the local repository, for use as a dependency in other projects locally.

Q23. Find details on the dependencies for the project.
using command,
mvn dependency:tree

Q24. What is a Maven project’s fully qualified artifact name?
<groupId>:<artifactId>:<version>

Q25. Order by which Maven searches for the dependency.
Local ->
Remote ->
Maven Central

Q26. What is groupId.
Identifies a project uniquely across all projects.

Q27. What is Maven plugin.
plugin is a distribution of one or more related mojos.

POM.
POM (Project Object Model) is the fundamental unit of work. It is an XML file which holds the information about the project and configuration details used to build a project by Maven along with its dependencies.

Q28. What makes a fully qualified name for the artifact? what uniquely identifies an artifact?
Three properties group ID, artifact ID and the version string together identifies the artifact.

Q29. What are the steps involved in project deployment?
There are several steps to follow while implying project deployment in Maven. These steps include:
1. Go through all the projects and analyze the code that is working in the background in progress in the source code repository and identifies it.
2. In order to get the project development, one need to download the whole source code from the Social Venture Network.
3. Construct or develop the application in the system
4. It needs to be saving as a War or Jar file system.
5. Get the specified file from the location path and move that specific file to create a site.
6. The application that is created in the system needs to be updated with the latest version with date and version number.

Q30. Explain the difference phases in Maven build Lifecycle.
Maven build lifecycle is defined by a list of build phases, where a build phase represents a stage in the lifecycle.
The default lifecycle comprises of the following phases.

validate – validates the project is correct and all necessary information is available.
compile – compile the source code of the project.
test – tests the compiled source code using a suitable unit testing framework. These tests does not require the code to be packaged or deployed.
package – take the compiled code and package it to its distributable format, for example, JAR.
verify – runs any checks on results of integration tests to ensure desired quality criteria are met.
install – installs the package into the local repository, for using it as a dependency in other projects locally.
deploy – performed in the build environment, copies the final package to the remote repository for sharing and collaboration with other members of the team and projects.

Summary
Review Date
Reviewed Item
Excellent!! Maven Interview Questions and Answers, thank you Iteanz.com.
Author Rating
51star1star1star1star1star