Here are multiple-choice questions (MCQs) on Maven, covering prerequisites, Maven's purpose, adding dependencies, referencing JAR files in local repositories, creating Maven projects, and importing existing Maven projects in Eclipse and through the command prompt.
1. What are the prerequisites for installing Maven on a system?
A) JDK and Git
B) JDK and Apache Server
C) JDK and Apache Ant
D) JDK and environment variables properly set
Answer: D) JDK and environment variables properly set
2. What is Apache Maven?
A) A build automation tool used primarily for Java projects
B) A version control system
C) A code editor for Java development
D) A continuous integration tool
Answer: A) A build automation tool used primarily for Java projects
3. Which file is used to configure a Maven project and manage dependencies?
A) maven.xml
B) build.xml
C) pom.xml
D) settings.xml
Answer: C) pom.xml
4. How do you add a dependency to a Maven project?
A) By writing the dependency details in build.xml
B) By writing the dependency details in pom.xml under the <dependencies> section
C) By downloading JAR files and placing them in the lib directory
D) By setting dependencies in settings.xml
Answer: B) By writing the dependency details in pom.xml under the <dependencies> section
5. Which command is used to create a new Maven project from the command line?
A) mvn create
B) mvn new project
C) mvn archetype:generate
D) mvn generate:archetype
Answer: C) mvn archetype:generate
6. What is the local repository in Maven?
A) A folder inside the Maven installation directory
B) A directory on the local machine where Maven stores downloaded dependencies
C) A remote server where dependencies are fetched from
D) A Git repository
Answer: B) A directory on the local machine where Maven stores downloaded dependencies
8. What is the standard directory structure for a Maven project?
A) src/, test/, lib/
B) src/main/java/, src/main/resources/, src/test/java/
C) src/java/, src/resources/, src/tests/
D) main/java/, main/resources/, test/java/
Answer: B) src/main/java/, src/main/resources/, src/test/java/
9. How do you create a Maven project in Eclipse?
A) File > New > Project > Java Project
B) File > New > Other > Maven Project
C) File > Import > Existing Maven Project
D) File > New > Maven > Maven Project
Answer: B) File > New > Other > Maven Project
10. Which Maven command is used to compile a project?
A) mvn build
B) mvn compile
C) mvn package
D) mvn install
Answer: B) mvn compile
11. How do you import an existing Maven project into Eclipse?
A) File > Open > Maven Project
B) File > Import > General > Existing Project into Workspace
C) File > Import > Maven > Existing Maven Projects
D) File > New > Maven Project
Answer: C) File > Import > Maven > Existing Maven Projects
12. What is the purpose of the dependencyManagement section in a pom.xml file?
A) To manage the versions of dependencies globally for a multi-module Maven project
B) To add dependencies to the project
C) To list all plugins used in the project
D) To configure Maven settings
Answer: A) To manage the versions of dependencies globally for a multi-module Maven project
13. Which Maven command is used to build the project and its dependencies?
A) mvn build
B) mvn package
C) mvn compile
D) mvn install
Answer: D) mvn install
15. When creating a Maven project from the command line, which archetype is commonly used for a simple Java application?
A) maven-archetype-quickstart
B) maven-archetype-webapp
C) maven-archetype-simple
D) maven-archetype-basic
Answer: A) maven-archetype-quickstart
17. How can you update a Maven project's dependencies in Eclipse?
A) Right-click the project > Maven > Update Project
B) Right-click the project > Refresh
C) Right-click the project > Run As > Maven Clean
D) Right-click the project > Build Path > Configure Build Path
Answer: A) Right-click the project > Maven > Update Project
19. How do you build a Maven project from the command prompt?
A) Navigate to the project directory and run mvn build
B) Navigate to the project directory and run mvn compile
C) Navigate to the project directory and run mvn clean install
D) Navigate to the project directory and run mvn package
Answer: C) Navigate to the project directory and run mvn clean install
20. Which command is used to run unit tests in a Maven project?
A) mvn test
B) mvn compile
C) mvn verify
D) mvn package
Answer: A) mvn test
These questions cover the key concepts and practical usage scenarios related to Maven, including its installation prerequisites, functionality, dependency management, project creation and import in Eclipse, and the Maven build lifecycle.
No comments:
Post a Comment