The Maven Interview Q&A section covers the most common and useful Maven interview questions for fresher's as well as experienced candidates. Basics to advanced concepts of Maven are covered in this section.
If you have attended any interview in the recent past, do paste the Maven interview questions asked to you in the comments section and we’ll answer them ASAP. You can also comment below any questions you have in your mind, which you might face in your interviews.
Question: Explain what is Maven? How does it work?
Answer: Maven is a project management tool. It provides the developer 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.
Question: What are the main features of Maven?
Answer: Some of the main features of Maven are:
- Simple to use: Maven provides easy project settings that are based on genuine practices.
- Fast: You can receive a fresh project or module that began in fewer seconds in Maven.
- Easy to learn: Maven usage and commands are pretty easy to learn across all projects. Therefore ramp-up time for new developers coming onto a project is very less.
- Dependency management: Maven provides superior dependency management including automatic updates and transitive dependencies.
- Multiple Projects: You can easily work on multiple projects at the same time by using Maven.
- Huge Library: Maven has a large and growing repository of libraries and metadata to use out of the box.
Question: What does the build tool?
Answer:
- Generates source code (if the auto-generated code is used)
- Generates documentation from source code
- Compiles source code
- Packages compiled code into a JAR or ZIP file
- Installs the packaged code in the local repository, server repository, or central repository
Question: Why should one use Maven?
Answer:
- It aids in setting up the project very quickly and it avoids complicated build files like build.xml. the pom.xml file is at the core of Maven.POM.xml is a collection of dependencies of your Java Project which one can specify to Maven. After this Maven will download all of them from the internet and store it to some repository i.e. local repository, central repository, and remote repository.
- It helps to bundle all the jars in your package i.e. in your War file or Ear file because all of them will be stored in the repository. So next time wherever you install this application that repository will be used for any dependencies lookup. In this way, your deployment file will be very light.
Question: List out what are the aspects does Maven Manages?
Answer: Maven handles following activities of a developer:
- Build
- Documentation
- Reporting
- Dependencies
- SCMs
- Releases
- Distribution
- Mailing list
Question: Mention the three build lifecycle of Maven?
Answer:
- Clean: Cleans up artifacts that are created by prior builds
- Default (build): Used to create the application
- Site: For the project generates site documentation
Question: Explain what is POM?
Answer: 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.
Question: Explain what is Maven artifact?
Answer: 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 a group ID, an artifact ID and a version string.
Question: Explain what is Maven Repository? What are their types?
Answer: A Maven repository is a location where all the project jars, library jars, plugins or any other particular project related artifacts are stored and can be easily used by Maven.
Their types are local, central and remote
Question: Why Maven Plugins are used?
Answer: Maven plugins are used to:
- Create a jar file
- Create war file
- Compile code files
- Unit testing of code
- Documenting projects
- Reporting
Question: List out the dependency scope in Maven?
Answer: The various dependency scope used in Maven are:
- Compile: It is the default scope, and it indicates what dependency is available in the classpath of the project
- Provided: It indicates that the dependency is provided by JDK or web server or container at runtime
- Runtime: This tells that the dependency is not needed for compilation but is required during execution
- Test: It says dependency is available only for the test compilation and execution phases
- System: It indicates you have to provide the system path
- Import: This indicates that the identified or specified POM should be replaced with the dependencies in that POM’s section
Question: Mention how profiles are specified in Maven?
Answer: Profiles are specified in Maven by using a subset of the elements existing in the POM itself.
Question: Explain how you can exclude dependency?
Answer: By using the exclusion element, dependency can be excluded
Question: Mention the difference between Apache Ant and Maven?
Answer: Apache Ant Maven
- Ant is a toolbox - Maven is a framework
- Ant does not have formal conventions like project directory structure - Maven has conventions
- Ant is procedural; you have to tell to compile, copy and compress - Maven is declarative ( information on what to make & how to build)
- Ant does not have lifecycle; you have to add sequence of tasks manually - Maven has a lifecycle
- Ant scripts are not reusable - Maven plugins are reusable
Question: In Maven what are the two setting files called and what are their location?
Answer: In Maven, the setting files are called settings.xml, and the two setting files are located at
- Maven installation directory: $M2_HOME/conf/settings.xml
- User’s home directory: ${ user.home }/ .m2 / settings.xml
Question: List out what are the build phases in Maven?
Answer: Build phases in Maven are:
- Validate
- Compile
- Test
- Package
- Install
- Deploy
Question: List out the build, source and test source directory for POM in Maven?
Answer:
- Build = Target
- Source = src/main/java
- Test = src/main/test
Question: Where do you find the class files when you compile a Maven project?
Answer: You will find the class files ${basedir}/target/classes/.
Question: Explain what would the “jar: jar” goal do?
Answer: jar: jar will not recompile sources; it will imply just create a JAR from the target/classes directory considering that everything else has been done
Question: List out what are the Maven’s order of inheritance?
Answer: The maven’s order of inheritance is
- Parent Pom
- Project Pom
- Settings
- CLI parameters
Question: For POM what are the minimum required elements?
Answer: The minimum required elements for POM are project root, modelVersion, groupID, artifactID and version.
Question: Explain how you can produce execution debug output or error messages?
Answer: To produce execution debug output you could call Maven with X parameter or e parameter.
Question: Explain how to run test classes in Maven?
Answer: 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."
No comments:
Post a Comment