Search Tutorials


Top Maven (2024) Interview Questions | JavaInUse

Maven Interview Questions


In this post we will look at Maven Interview questions. Examples are provided with explanation.

Q: What do you mean by build tools?
A:
Build tools are generally to transform source code into binaries - it organize source code, set compile flags, manage dependencies. Some of them also integrate with running unit test, doing static analysis, a generating documentation.

Q: Why do we use build tools or build automation?
A:
In small projects, developers will often manually invoke the build process. This is not practical for larger projects, where it is very hard to keep track of what needs to be built, in what sequence and what dependencies there are in the building process. Using an automation tool allows the build process to be more consistent. Some build tools available-:
  • For java - Ant,Maven,Gradle.
  • For .NET framework - NAnt
  • c# - MsBuild.
Q: Why Maven? What are its advantages?
A:
Advantages of maven are as follows -
  • Quick project setup, no complicated build.xml files, just a POM and go all developers in a project use the same jar dependencies due to centralized POM. getting a number of reports and metrics for a project "for free" reduce the size of source distributions, because jars can be pulled from a central location
  • Promotes modular design of code. by making it simple to manage mulitple projects it allows the design to be laid out into muliple logical parts, weaving these parts together through the use of dependency tracking in pom files. Enforces modular design of code.


Q: What do you mean by archetype?
A:
Archetype is a Maven project templating toolkit. An archetype is defined as an original pattern or model from which all other things of the same kind are made.

Q: Can you create a custom archetype?
A:
Yes we can create a custom archetype. For example, in our project we created a archetype which would create a custom maven projects with modules as DAO, SERVICE and WEB. These modules had the required dependencies. All project members used this archetype as it saved a lot of time and every one had same starting workspace.


Q: What is a maven artifact?
A:
An artifact is a file, usually a JAR, that gets deployed to a Maven repository. A Maven build produces one or more artifacts, such as a compiled JAR and a "sources" JAR.
Each artifact has a group ID (usually a reversed domain name, like com.javainuse), an artifact ID (just a name), and a version string. The three together uniquely identify the artifact.
A project's dependencies are specified as artifacts.

Q: How Maven searches for dependency JAR?
A:
Maven uses the concept of the repository to hold the jar files. There are two types of repository namely local and remote repository. Example in your eclipse, create a maven project. Every maven project has a pom.xml file.
Right click the pom.xml file → run as → maven install.
Now it checks your local repository for the jar files. If the jar files are not found it goes to the remote repository and download the jar.
Q: What is pom.xml file?
A:
A Project Object Model or POM is the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used by Maven to build the project. It contains default values for most projects. Examples for this is the build directory, which is target; the source directory, which is src/main/java; the test source directory, which is src/main/test; and so on. The POM was renamed from project.xml in Maven 1 to pom.xml in Maven 2. Instead of having a maven.xml file that contains the goals that can be executed, the goals or plugins are now configured in the pom.xml. When executing a task or goal, Maven looks for the POM in the current directory. It reads the POM, gets the needed configuration information, then executes the goal.

Q: What is dependency tag used for in pom.xml?
A:
Using dependency tag we give info as to which groupId, artifactId, and version does this project depends on.

Q: Define the phases of a maven build life cycle?
A:
  • clean - clean artifactory which was created earlier
  • build - creates the application
  • Site - generates the document


Q: What is the command to skip maven test cases?
A:
In order to skip tests run the following command -
mvn package -Dmaven.test.skip=true

Q: What are the different scopes of maven dependencies?
A:
  • Compile - Dependency is inserted at compile time. This is the default scope
  • Runtime - Dependency is inserted at runtime
  • Test - Dependency will be inserted only during test cases execution
  • Provided - This means the project does not need to insert the dependency , as this dependency will be provided by the container when the application is deployed


Q: Can you install external jar to maven repository ?
A:
In order to install the jar as maven dependency use the following command -
mvn install:install-file -Dfile={jar name with location path} -DgroupId={groupid} -DartifactId={artifactId} -Dversion={version} -Dpackaging=jar
ex - mvn install:install-file -Dfile={C:/test-1.0.0-SNAPSHOT.jar} -DgroupId={com.javainuse} -DartifactId={test} -Dversion={1.0.0-SNAPSHOT} -Dpackaging=jar

See Also

Spring Batch Interview Questions Apache Camel Interview Questions JBoss Fuse Interview Questions Drools Interview Questions Java 8 Interview Questions