Maven Interview Questions

By YuwebDesign

Maven is a project management tool.

It provides the developer with a complete build lifecycle framework.

On executing Maven commands, it will look for POM file in Maven;
it will run the command on the resources described in the POM.

Maven handles following activities of a developer

  1. Build
  2. Documentation
  3. Reporting
  4. Dependencies
  5. SCMs
  6. Releases
  7. Distribution
  8. Mailing list

  1. Clean:
    Cleans up artifacts that are created by prior builds
  2. Default (build):
    Used to create the application
  3. Site:
    For the project generates site documentation

Build phases in Maven are

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

In Maven, 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.

  1. Build = Target
  2. Source = src/main/java
  3. Test = src/main/test

The minimum required elements for POM are

  1. project root,
  2. modelVersion,
  3. groupID,
  4. artifactID
  5. and version

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

  1. a group ID,
  2. an artifact ID
  3. and a version string.

A Maven Repository
is a location where all the

  1. project jars,
  2. library jars,
  3. plugins
  4. or any other particular project related artifacts

are stored
and can be easily used by Maven.

Maven Repository Types are

  1. local,
  2. central
  3. and remote

Maven plugins are used to

  1. Create a jar file
  2. Create war file
  3. Compile code files
  4. Unit testing of code
  5. Documenting projects
  6. Reporting

The variations of dependency scope used in Maven are:

  1. Compile: It is the default scope, and it indicates what dependency is available in the classpath of the project
  2. Provided: It indicates that the dependency is provided by JDK or web server or container at runtime
  3. Runtime: This tells that the dependency is not needed for compilation but is required during execution
  4. Test: It says dependency is available only for the test compilation and execution phases
  5. System: It indicates you have to provide the system path
  6. Import: This indicates that the identified or specified POM should be replaced with the dependencies in that POM’s section

Profiles are specified in Maven
by using a subset of the elements
existing in the POM itself.

Dependency can be excluded
by using the exclusion element.

  1. Ant is a toolbox
    Maven is a framework
  2. Ant does not have formal conventions like project directory structure
    Maven has conventions
  3. Ant is procedural;
    you have to tell to compile, copy and compress

    Maven is declarative
    information on what to make & how to build

  4. Ant does not have lifecycle;
    you have to add sequence of tasks manually

    Maven has a lifecycle

  5. Ant scripts are not reusable
    Maven plugins are reusable

In Maven, the setting files are called settings.xml,
and the two setting files are located at

  1. Maven installation directory:
  2. User’s home directory:
    ${ user.home }/ .m2 / settings.xml

You will find the class files at

jar: jar
will not recompile sources;

it will simply just create
a JAR from the target/classes directory
considering that everything else has been done.

The maven’s order of inheritance is

  1. Parent Pom
  2. Project Pom
  3. Settings
  4. CLI parameters

To produce execution debug output
you could call Maven with

  1. X parameter
  2. or e parameter

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.”

Sources: career.guru99.com, edurica.co, educba.com

Leave a Reply or Comment

Your email address will not be published. Required fields are marked *