Top 10 Maven Interview questions and answers
Q1. What do you understand by maven software?
A powerful project management tool based on project object model is known as maven software. It helps in building projects, dependency, and documentation. Just like ANT does, it makes the build process simpler but is much more advanced than ANT. It is a build automation tool which is basically used for java projects. “Maven” is a Yiddish word which means “accumulator of knowledge”. It describes how actually software is built and also specifies its dependencies. In this, the conventional method is used for the build procedure. The Java libraries are dynamically downloaded by Maven. Even the projects are written in C#, Ruby, Scala and some other languages can be built and managed by Maven. A plug-in based architecture is used to build Maven which allows it to make use of any application which can be controlled through any standard input.
Q2. What are some problems which we face while the development of a project when Maven is not used?
Following is a list of some problems which we face while developing a project when Maven is not used: –
- Addition of set of jars in each project- when struts, spring, hibernate frameworks are used then a set of jar files needs to be added in each project. All the dependencies of jars should also be included.
- Creating a right project structure- for the execution of a project, a right project structure should be created in servlet, struts, etc. otherwise it won’t get executed.
- Building and deployment of a project- the project should be built and deployed so that it works and provides us with the desired output.
Q3. What are the tasks which are performed by Maven?
All the problems which are mentioned above are simplified by Maven and it performs various tasks which are as follows: –
- A project can be easily built when using Maven.
- A uniform build process is provided by Maven.
- All the information regarding the project is provided by Maven. Information like- log document, cross-referenced sources, mailing list, dependency list, unit test reports, etc.
- New features of Maven are easy to migrate.
- Apache Maven helps in managing the following attributes-
Q4. What is the role of a build tool in Apache Maven?
Everything which is used for building any software is handled by a build tool in Apache Maven. It is used for the following few processes: –
- For generating a source code only if an auto-generated code is used.
- It is also used for generating documentation from the source code.
- It is used for the compilation of the source code.
- The packages which are compiled with the help of Maven are compiled into a JAR of a ZIP file.
- The packaged code in Maven is installed in the local repository, server repository, or central repository.
Q5. List the differences between ANT and Maven.
The differences between ANT and Maven are listed below: –
- Formal conventions are not present in ANT, due to which we need to provide the information of the project structure. Whereas, Maven has conventions which are needed to place the source or compiled the code. And hence we don’t need to provide the information.
- ANT is a procedural language which provides information about what to do and when to do. Whereas, Maven is a declarative language in which we define everything in the pom.xml file.
- ANT does not contain any life cycle. Whereas, there is a life cycle in Maven.
- ANT is a toolbox. Whereas, Maven is a framework.
- ANT is mainly a build tool. Whereas, Maven is basically a management tool.
- ANT scripts are not reusable. Whereas, Maven scripts are reusable.
- ANT scripts are less preferred. Whereas, Maven scripts are more preferred.
Q6. Write the steps for installing Maven on windows.
Maven can be downloaded and installed on windows, linux, and MAC OS platforms. Here are the steps given for installing Maven on windows operating system. For installing Maven on windows, you need to perform the following steps:
- Download Maven and extract it.
- Add JAVA_HOME and MAVEN_HOME in the environment variable.
- Add the environment path in Maven variable.
- The final step is the verification of Maven.
Q7. What do you mean by Maven repository and its types?
A directory of packaged JAR file which also consists of pom.xml file is called a Maven repository. Dependencies are being searched in the Maven repositories. There are basically three types of repositories. They are –
- Local repository- the local repository of Maven is located in the local system. It is created in the system when any Maven command is run.
- Central repository- the central repository is located on the web. The apache Maven community creates this repository by itself.
- Remote repository- the remote repository is also located on the web. It consists of such libraries which are missing from the central repository.
Maven first searches for the local repository, then the central and then the remote repository. If dependencies are not found, then Maven stops the execution and throws an error.
Q8. Throw some light on the pom.xml file in Maven.
Here, the full form of POM is project object model. This model consists of all the information about the project. It also consists of the configuration information for the Maven to build the project. It contains the dependencies, build directory, source directory, test source directory, plugin, goals, etc. First the pom.xml file is read and then only the goal is executed. Firstly this pom.xml file was named as project.xml file but after the release of the latest version, it was changed to pom.xml file. There are basically five elements which are used to create a pom.xml file. They are: –
Q9. List all the dependency scope in Maven.
The following are the various dependency scope used in Maven: –
- Compile- it is the default scope and it also tells whether the dependency is available or not.
- Provided: it tell us that the dependency is provided dynamically i.e. at run time.
- Run time: it gives us the information that the dependency is not needed for compilation but is needed at the time of execution.
- Test: it says that dependency is available on for the test compilation and execution phases.
- System: it tells us that the system path needs to be provided.
- Import: it indicates that the dependency in the POM’s section should be placed in place of the identified POM.
Q10. What are the three build life cycles of Maven? Mention them.
The three build life cycles of Maven are given below: –
- Clean- using this, the artefacts which are created by the prior build are cleaned.
- Default (build)- it is used for creating the application.
- Site- it is used for the projects and for generating site information.