Maven Interview Questions and Answers

Maven Interview Questions and Answers

Last updated on 19th Oct 2020, Blog, Interview Question

About author

Kernel ((Team Lead - WPF ) )

High level Domain Expert in TOP MNCs with 8+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 16392 Ratings 2363

Roles requiring knowledge, skills and experience in Maven involve many intense interview questions. Employers use these questions to ensure you’re ready to address any Maven issue that arises. This includes any sort of code or function required to solve a problem. In this article, we list general questions, experience questions, in-depth questions and offer examples answers to eleven technical questions

1. Who developed Maven?

Ans:

Apache software foundations

2. In which language is Maven written?

Ans:

Java

3. State the latest Maven license?

Ans:

Apache license 2.0

4. Define Maven tool?

Ans:

Maven is a build automation tool used for java projects, sofware or applications.

5. Do you understand build tools?

Ans:

These are tools used for to transform source code into binaries – it organizes source code, sets compile flags and manages dependencies.

The tools also sometimes integrate with running unit tests, doing static analysis, a generating documentation.

6. Explain why developers use build tools or build automation?

Ans:

  The developers have high tendencies of manually invoking the build process in relatively small projects. On the contrary, the larger projects cannot be handled manually because it is hard to track of every aspect of the software that needs to be built. It is also difficult to the developer to keep track of the sequence and the dependencies of the building process. For this purpose the automation tools help developers to be more consistent.

7. Give examples of build tools available in market today?

Ans:

  • For java – Ant, Maven,Gradle.
  • For .NET framework – NAnt
  • C# – MsBuild.

8. Why do developers use Maven?

Ans:

Engineers and developers use it because it is a powerful project management tool that is based on POM.

It is used for project building or compiling, dependency and documentation.

The Maven repo is a directory of packaged JAR files with POM.XML files.

Additionally Maven searches for dependencies in the repository.

9. Describe the main advantages of using Maven as a developer?

Ans:

Quick project setup.

No complicated build.xml files.

The developers benefit from a software in that they can they can use the jar dependencies due to a centralized POM.

Developers also benefit from reports and metrics for a project “for free”.

There is reduced size of source distribution because jars can be pulled form central location.

Promotes modular design code and this makes it possible to manage multiple projects.

Enforces modular design of code.

Has a strong defined lifecycle.

Developers can mix and match system to lifecycle and this allows them to move from one project to another and speak using the same vocabulary in terms of software building.

10. Define a Maven POM file?

Ans:

POM is acronym for project object model.

POM is a central unit of work in Maven.

It is an XML file that comprises the information about the project and configuration details used by Maven to build projects. • The file carries the default values of most projects.

11. Describe repositories as they occur in Maven?

Ans:

A repository or repo as some people call it, is a directory that carries project jars, library jar, plugins and other specific artifacts and can be used to aces the jars easily.

12. Explain an artifact in Maven?

Ans:

Artifacts are files that are usually deployed to a Maven repository.

Maven processes can process artifacts such as complied JAR and a “sources” JAR.

Artifacts bears group ID – these occurs as a reversed domain name like com.example.foo

The artifact also comes with a unique ID which is a unique name and a version string.

13. Explain a Maven dependency?

Ans:

When developers are running Maven on a project B version 1.0 of artifacts a, b, c, and d, will be used despite the version specified in their POM. A and c will be declared as dependencies of the project do version 1.0 is used due to dependency mediation. Both will have a runtime scope because they are directly specified.

14. Explain how Maven searches for dependency JAR?

Ans:

The concept of repository is used to hold jar files in Maven.

In Maven there are local and remote repository.

The syntax for searching dependency jar is as follows;

Right click the

  • pom.xml file → run as → Maven install.

If the jars are not found in the local repository it will search in remote section and download the needed files.

15. Explain the job of the Maven dependency plugin?

Ans:

Engineers has recently come up with the apache Maven dependency plugin.

The plugin allows developers to manipulate artifacts.

It can copy and unpack artifacts from local or remote repository to a specified location.

16. Why are plugins used in Maven?

Ans:

Maven has a set of plugins; they are tools used to create jar files:

Create war files.

Compile code.

Unit test code.

Create project documentation.

17. What is pom.xml file?

Ans:

This is a fundamental unit of work in Maven.

It bears all the project information.

POM was renamed from project.xml in Maven 1 to pom.xml in Maven 2.

In this regard the goals and plugins are now configured in the pom.xml.

When developers are executing a tasks or goal, Maven looks for the POM in the current directory. It does It by reading the POM, getting the required configuration information and then executing the goal

Subscribe For Free Demo

Error: Contact form not found.

18. What aspects does Maven manage in project building?

Ans:

  • Builds.
  • Documentation.
  • Reporting.
  • Dependencies.
  • SCMs.
  • Releases.
  • Distribution.
  • Mailing lists.

19. Explain how Maven uses convention over configuration?

Ans:

The statement that Maven uses convention over configuration means that developers are not obliged to create build process themselves.

The developers are not required to mention each and every configuration details.

20. Give the method that would be used to identify the version of Maven you are using?

Ans:

Mvn—Version

21. List the configuration information carried by Pom?

Ans:

  • Project dependencies.
  • Plugins.
  • Goals.
  • Build profiles.
  • Project version.
  • Developers.
  • Mailing list.

22. Describe what a goal is?

Ans:

By executing a phase it means that the developer is executing all the previous phases.

Plugins in Maven are considered to be a collection of goals.

Plugin is a class while a goal is a method within a class.

Maven performs its work by the concept of a build lifecycle.

23. Explain the location where the Maven dependencies are downloaded?

Ans:

The jars and the dependency files are downloaded into the Maven local repository.

By default this local repository is marked .m2 folder.

It is also possible to copy the jar directly into the location is meant be used. Maven will easily locate such a file or jar.

24. What is Maven build lifecycle?

Ans:

  The build lifecycle is a well-defined sequence of phases that outline the order in which the goals are to be executed. Typically the phase represents a stage in the life cycle.

25. List 3 build lifecycle in Maven?

Ans:

Clean- this is the process of cleaning up artifacts created by previous builds.

Default or build – this is the process of building the appliance.

Site- this will generate site documentation for project.

26. Describe the phases of a Maven build lifecycle?

Ans:

Validate– when the you validate the project it means that the project is checked if tis correct and all the useful information is provided.

Compile– in this phase the developers compile the source code of the project.

Test– in this stage the develop will test the compiled code employing an appropriate unit testing framework and the tests should not be require the code deployed or packaged.

Package– the developer takes the compiled code and packages it in its distributable format like a JAR.

Integration test– this is where the developer processes and deploys the package if necessary into an atmosphere wherever integration tests may be run.

Verify– this entails running tests to asses I the package is still valid and meets the quality requirements.

Install – this is the phase in which the package is installed into the native repository and will later be used and a dependency in alternative projects regionally.

Deploy– in this phase the final package is copied into the remote repository for sharing with alternative projects and developers. This process is den in integration or release environment.

27. Mention various types of Maven repositories?

Ans:

  • Local repository.
  • Central repository.
  • Remote repository.

28. Define a Maven snapshot?

Ans:

Snapshot is an incomplete version of Maven and is not yet ready for release. A similar version will get several updates.

In this version, the exposure dependencies usually exist on their own throughout the development process and no free version have a dependency on a snapshot version.

29. What are essential features of a build tool?

Ans:

  A build tool should have:

Capacity to compile java code and build jar, war and ear flies for development and release.

Versioning and dependency management.

Run checks and reports test results.

Run code quality check with sonar, check style and detect bugs.

Environment property substitution.

Files generations such as WSDL, AspectJ, XSL among other.

Support for cross platform (Unix windows ) and IDEs (Eclipse, Netbeans and IntelliJ)

Proper documentation and support

30. Describe the dependency scope in Maven?

Ans:

  The popular dependency scope in Maven includes the following;

Compile – this is basically the default scope. It shows what dependency is provided within the class path of the project

Provided- this scope highlights if the dependency is offered by JDK or internet server or a container a runtime

Runtime – this indicate that the dependency is not required for compilation but is needed throughout the execution

Test- this highlights that dependency is offered just for the take a look at compilation an execution phases

System- it indicates that the developer will need to give the system path

Import – This shows that the known or normative pom should be replaced with the dependencies in this POM’s section.

31. Define the Maven assembly?

Ans:

The assembly plugin if basically used to allow users to aggregate the project output along with its dependencies, modules, site documentation and other files into a single distributable archive.

32. Describe Mojo as it occurs in Maven?

Ans:

This is the abbreviation for Maven plain old java object.

Typically a mojo is an executable goal in Maven and a plugin is a distribution of one or more related mojos.

In this context a mojo can simply be termed as an executable Maven goal and extend the functionality that would not be available in Maven.

33. Give the quick command to build Maven site?

Ans:

This is done by typing the following command; mvn site.

34. What is the work of command mvn clean?

Ans:

This command is used to remove the target directory with all the build data before starting the build process.

35. What would happen when you type the command Mvn clean dependency: copy – dependencies package?

Ans:

It is will clean all the project, copy the dependencies and package the project.

The command will complete all phases up to the package phase.

36. List the phases of a clean lifecycle?

Ans:

  • Pre-clean
  • Clean
  • Post-clean

37. List the phases of a site lifecycle?

Ans:

  • Pre-site
  • Site
  • Post site
  • Site-deploy

38. Define a build profile?

Ans:

  These are a set of configuration values that can be utilized to set or override default values of Maven build. Developers use them to customize build for different environments including Production v/s development environments.

39. List varies types of build profiles? 

Ans:

Per project- they are defined in the project Pom file, pom.xml.

Per user- these are defined in Maven settings xml file

  • (%USER_HOME%/.m2/settings.xml)

Global- these are defined in Maven settings xml file

  • (%M2_HOME%/conf/settings.xml)

40. Describe how you would activate profiles?

Ans:

Explicitly using the command console input

Through Maven settings

Based on environment variables (User/System variables)

OS settings mostly in windows family

Present/ missing files

41. State the default location for the local repository?

Ans:

  • ~/m2./repository.

42. Give the command for installing jar file in the local repository?

Ans:

  • MVN install

43. Define the central repository?

Ans:

This is a repository given by the Maven community. Typically is carries large volumes of commonly used libraries When the software fails to find any dependency in local repository, it starts searching in central repository using the following link; http://repo1.Maven.org/Maven2/.

Course Curriculum

Get Maven Certification Course with Industry Standard Modules

Weekday / Weekend BatchesSee Batch Details

44. Describe the sequence you would utilize to search for dependencies libraries?

Ans:

Searching in local repository and if the dependencies are not found you move to the next step. If found the developer will proceed with further processing.

The next step is to search in central repository. If not found move to next step but is found you download it to local repository for future reference.

The third step occurs when the remote repository has not been mentioned, Maven will cease processing and will throw errors (indicating it has failed in finding a dependency).

In step four, the search dependency in remote repository is downloaded to local repository for future reference and if this fail Maven will throw an error.

45. State the use of Maven plugins?

Ans:

Creating jar file.

  • Creating war file.
  • Compiling code files.
  • unit testing of code.
  • Creating project documentation.
  • Creating project reports.

46. Describe the popular types of plugins in Maven?

Ans:

Build plugins- they are used in execution doing the build and needs to be configured in the element of pom.xml

Reporting plugins- they execute during the site generation and they should be configured in the element of the pom.xml

47. Where are Maven dependencies stored?

Ans:

In Maven local repository

48. Define archetype in Maven?

Ans:

This is a Maven project templating toolkit.

This is an original pattern or model form which all other things of the same kind are made.

The Maven archetype is meant to provide a consistent means of generating Maven projects.

49. Explain the advantages of Maven over Ant?

Ans:

The convention over configuration ability makes it easy to jump into the project.

In Maven the developer will do it using checkout and the Maven command to get the artifacts of the project.

Project modularization means that h developer has the ability to modularize the project. The developer will not be compelled to divide the project tint smaller sub components, which makes it easier to debug and manage the overall project structure.

Maven allows developers to do dependency management and project lifecycle. This means that with a good SCM configuration and internal repository, the dependency management will be possible.

Maven seems to be a little complex that ant because of lifecycle but this provides an improvement in quality of the project

50. What are the disadvantages of Maven?

Ans:

Maven is relatively hard to work with.

The build cycle might not be clear to developers.

There might be issues with the quality of components and missing dependencies in public repositories.

51. Describe how you would tell Maven to use the latest versions of a dependency?

Ans:

  The most popular setup of dependencies in Maven is as follows;

  • <dependency>
  • <groupId>wonderful-inc</groupId>
  • <artifactId>dream-library</artifactId>
  • <version>1.2.3</version>
  • </dependency>

When working with Maven 2, the developer will need to always want to use the newest version. There are two keywords that can be used as an alternative of version ranges. It is useful to note that you are not in control of and dependencies and therefore you have to use the keywords with care.

A square bracket ( [ & ] ) means “closed” (inclusive).

A parenthesis ( ( & ) ) means “open” (exclusive).

Here’s an example illustrating the various options. In the Maven repository, com.foo:my-foo has the following metadata:

  • <?xml version=”1.0″ encoding=”UTF-8″?><metadata>
  • <groupId>com.foo</groupId>
  • <artifactId>my-foo</artifactId>
  • <version>2.0.0</version>
  • <versioning>
  • <release>1.1.1</release>
  • <versions>
  • <version>1.0</version>
  • <version>1.0.1</version>
  • <version>1.1</version>
  • <version>1.1.1</version>
  • <version>2.0.0</version>
  • </versions>
  • <lastUpdated>20090722140000</lastUpdated>
  • </versioning>
  • </metadata>

The alternative of the above methods is to declare the an exact versions (this will always resolve to 1.0.1):

  • <version>[1.0.1]</version>

Declare an explicit version (will always resolve to 1.0.1 unless a collision occurs, when Maven will select a matching version):

  • <version>1.0.1</version>

Declare a version range for all 1.x (will currently resolve to 1.1.1):

  • <version>[1.0.0,2.0.0)</version>

Declare an open-ended version range (will resolve to 2.0.0):

  • <version>[1.0.0,)</version>

Declare the version as LATEST (will resolve to 2.0.0) (removed from Maven 3.x):

  • <version>LATEST</version>

Declare the version as RELEASE (will resolve to 1.1.1) (removed from Maven 3.x):

  • <version>RELEASE</version>

Note that by default your own deployments will update the “latest” entry in the Maven metadata, but to update the “release” entry, you need to activate the “release-profile” from the Maven super POM. You can do this with either “-Prelease-profile” or “-performRelease=true”

52. Explain how you would create an executable JAR with dependencies using Maven?

Ans:

  If a developer wants to package a project into a single executable jar distribution they will need to package all dependencies jar into one jar. The processes below would be useful for the purpose;

You can use the dependency-plugin to generate all dependencies.

  • <build>
  • <plugins>
  • <plugin>
  • <artifactId>Maven-assembly-plugin</artifactId>
  • <configuration>
  • <archive>
  • <manifest>
  • <mainClass>fully.qualified.MainClass</mainClass>
  • </manifest>
  • </archive>
  • <descriptorRefs>
  • <descriptorRef>jar-with-dependencies</descriptorRef>
  • </descriptorRefs>
  • </configuration>
  • </plugin>
  • </plugins>
  • </build>

And you run it with

mvn clean compile assembly:single

Compile goal should be added before assembly:single or otherwise the code on your own project is not included.

Thee method will help the Jar to build when executing mvn install or performing a deployment /release

The developer will then need to run the following commands:

  • <plugin>
  • <artifactId>Maven-assembly-plugin</artifactId>
  • <configuration>
  • <archive>
  • <manifest>
  • <mainClass>fully.qualified.MainClass</mainClass>
  • </manifest>
  • </archive>
  • <descriptorRefs>
  • <descriptorRef>jar-with-dependencies</descriptorRef>
  • </descriptorRefs>
  • </configuration>
  • <executions>
  • <execution>
  • <id>make-assembly</id> <!– this is used for inheritance merges –>
  • <phase>package</phase> <!– bind to the packaging phase –>
  • <goals>
  • <goal>single</goal>
  • </goals>
  • </execution>
  • </executions>
  • </plugin>

53. Explain situations where Maven uses external dependency concept?

Ans:

The Maven dependency management uses concept of Maven repositories. When dependency is not available in any of the remote repositories and central repository; in such scenarios Maven uses concept of external dependency.

54. Explain the things you need to define for each external dependency?

Ans:

The external dependencies can be configured in pom.xml in the same way as other dependencies

Some of the methods that can be used include the following;

Specifying groupID same as name of the library

Specifying artifactID same as name of the library

Specifying scope system

Specify system pat relative to project location

55. Give the command of creating a new project based on an archetype?

Ans:

  • mvn archetype:generate

56. Describe how you would convert inputstream into string?

Ans:

  The recommendable way for converting an input stream into a string is as follows;

  • public String convertStreamToString(InputStream is) {
  • // ???
  • }
  • it is also possible to use apache commons IOUtils to copy the InputStream into a StringWriter using the following method
  • StringWriter writer = new StringWriter();
  • IOUtils.copy(inputStream, writer, encoding);
  • String theString = writer.toString();
  • or even
  • // NB: does not close inputStream, you can use IOUtils.closeQuietly for that
  • String theString = IOUtils.toString(inputStream, encoding);

Alternatively, you could use ByteArrayOutputStream if you don’t want to mix your Streams and Writers

Maven Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

57. State the different ways you would convert an inputstream to a string?

Ans:

Using IOUtils.toString (Apache Utils)

  • String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);

Using charstreams (guava)

  • String result = CharStreams.toString(new)
  • InputStreamReader(
  • inputStream, Charsets.UTF_8));

Using Scanner (JDK)

  • Scanner s = new Scanner(inputStream).useDelimiter(“\\A”);
  • String result = s.hasNext() ? s.next() : “”;

Using Stream Api (Java 8). Warning: This solution convert different line breaks (like \r\n) to \n.

  • String result = new BufferedReader(new)
  • InputStreamReader(inputStream))
  • .lines().collect(Collectors.joining(“\n”));

Using parallel Stream Api (Java 8). Warning: This solution convert different line breaks (like \r\n) to \n.

  • String result = new BufferedReader(new)
  • InputStreamReader(inputStream)).lines()
  • .parallel().collect(Collectors.joining(“\n”));

Using InputStreamReader and StringBuilder (JDK)

  • final int bufferSize = 1024;
  • final char[] buffer = new char[bufferSize];
  • final StringBuilder out = new StringBuilder();
  • Reader in = new InputStreamReader(inputStream, “UTF-8”);
  • for (; ; ) {
  • int rsz = in.read(buffer, 0, buffer.length);
  • if (rsz < 0)
  • break;
  • out.append(buffer, 0, rsz);
  • }
  • return out.toString();
  • Using StringWriter and IOUtils.copy (Apache Commons)
  • StringWriter writer = new StringWriter();
  • IOUtils.copy(inputStream, writer, “UTF-8”);
  • return writer.toString();

Using ByteArrayOutputStream and inputStream.read (JDK)

  • ByteArrayOutputStream result = new ByteArrayOutputStream();
  • byte[] buffer = new byte[1024];
  • int length;
  • while ((length = inputStream.read(buffer)) != -1) {
  • result.write(buffer, 0, length);
  • }
  • // StandardCharsets.UTF_8.name() > JDK 7
  • return result.toString(“UTF-8”);

Using BufferedReader (JDK). Warning: This solution convert different line breaks (like \n\r) to line.separator system property (for example, in Windows to “\r\n”).

  • String newLine = System.getProperty(“line.separator”);
  • BufferedReader reader = new BufferedReader(new)
  • InputStreamReader(inputStream));
  • StringBuilder result = new StringBuilder();
  • String line; boolean flag = false;
  • while ((line = reader.readLine()) != null) {
  • result.append(flag? newLine: “”).append(line);
  • flag = true;
  • }
  • return result.toString();

Using BufferedInputStream and ByteArrayOutputStream (JDK)

  • BufferedInputStream bis = new BufferedInputStream(inputStream);
  • ByteArrayOutputStream buf = new ByteArrayOutputStream();
  • int result = bis.read();
  • while(result != -1) {
  • buf.write((byte) result);
  • result = bis.read();
  • }
  • // StandardCharsets.UTF_8.name() > JDK 7
  • return buf.toString(“UTF-8”);

Using inputStream.read() and StringBuilder (JDK). Warning: This solution has problem with Unicode, for example with Russian text (work correctly only with non-Unicode text)

  • int ch;
  • StringBuilder sb = new StringBuilder();
  • while((ch = inputStream.read()) != -1)
  • sb.append((char)ch);
  • reset();
  • return sb.toString();

58. Define transitive dependency in Maven?

Ans:

This means a developer will avoid needing to discover and specify the libraries that their dependencies require and includes them automatically.

59. State the value for packaging element in pom for a project that is purely meta-data?

Ans:

Pom

60. What is a projects fully qualified artifact name?

Ans:

  • <groupId>:<artifactId>:<version>

61. What are some of the differences between Maven and Ant?

Ans:

Maven comprises of conventions for source code placement, code compilation etc. This means that users don’t have to provide information about a project structure in pom.xml file. On the other hand, Ant lacks formal conventions such as the common project directory. This means that users have to provide information about the project structure in build.xml file.

Maven is declarative in nature and takes care of all the directories once the files are entered in the pom.xml file whereas Ant is procedural and users have to specify what needs to be done.

Maven has a lifecycle while Ant doesn’t.

Maven is a framework while Ant is a tool.

Maven is a project management tool while Ant is mainly a build tool.

Maven plugins are reusable while the scripts in Ant are not reusable.

in terms of user preference, Maven is the preferred choice compared to Ant.

62. What are the advantages of using an internal Maven private repository?

Ans:

An internal private repository reduces conflicts among likelihood versions.

A private repository requires less manual intervention to build first time.

Private internal repositories have a single central reference repository for all dependent software libraries as opposed to having several independent libraries.

Using an internal repository builds Maven projects faster since artifacts can be retrieved from the intranet server as opposed to being retrieved from an internet server.

63. What are the criteria/key considerations for choosing a Maven repository implementation?

Ans:

Free and open source.

Provide admin tools.

Easy to setup and use.

Provide backup facility.

Able to create, edit and delete sub repositories.

Anonymous read only access and also access control facility.

Deployable in any standard web server such as Tomcat or Apache.

Issue tracker, forums and other independent source of information.

Active community developers make the product enhanced and bugs fixed.

Bulk import/export facility to move groups of artifacts into the repository and out of the repository.

Provide a repository browser: should be a web browser instead of the desktop application.

64. How can one integrate static (x) html into Maven site?

Ans:

You can integrate your static pages in this several steps:

Put your static pages in the resources directory

  • ${basedir}/src/site/resources.

Create your site.xml and put it in

  • ${basedir}/src/site.
  • <project name=”Maven War Plugin”>
  • <bannerLeft>
  • <name>Maven War Plugin</name>
  • <src>http://Maven.apache.org/images/apache-Maven-project.png</src>
  • <href>http://Maven.apache.org/</href>
  • </bannerLeft>
  • <bannerRight>
  • <src>http://Maven.apache.org/images/Maven-small.gif</src>
  • </bannerRight>
  • <body>
  • <links>
  • <item name=”Maven 2″ xhref=”http://Maven.apache.org/Maven2/”/>
  • </links>
  • <menu name=”Overview”>
  • <item name=”Introduction” xhref=”introduction.html”/>
  • <item name=”How to Use” xhref=”howto.html”/>
  • </menu>
  • ${reports}
  • </body>
  • </project>

Link the static pages by modifying the <menu> section, create items and map it with the filename of the static pages.

  • <menu name=”Overview”>
  • <item name=”Introduction” xhref=”introduction.html”/>
  • <item name=”How to Use” xhref=”howto.html”/>
  • <item name=”<put-name-here>” xhref=”<filename-of-the-static-page>”/>
  • </menu>

Are you looking training with Right Jobs?

Contact Us

Popular Courses