Enroll in Selenium Training

This is the second method to create a Maven project. But in this rather than creating a project outside eclipse and then inport in to eclipse, we will directly create a maven project in to eclipse.

Create a New Maven Project in Eclipse

  1. Open your eclipse and Go to File > New > Others.

EclipseMaven_1

  1. Select Maven Project and click on Next.

EclipseMaven_2

  1. Un-check the 'Use default Workspace location' and with the help of the Browse button choose your workspace where you would like to set up your Maven project.

EclipseMaven_3

  1. Select the archetype, for now just select the 'maven-aechetype-quickstart' and click on Next.

EclipseMaven_4

  1. Specify the Group Id & Artifact Id and click on Finish.

EclipseMaven_5

Note: Here the ‘artifactId‘ is your project name.

6) Go to the project location to see the newly created maven project. Now open the pom.xml file, which resides in the project folder. By default the POM is generated like this:

<project xmlns="https://maven.apache.org/POM/4.0.0" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>ToolsQA</groupId>
  <artifactId>DemoMavenEclipseProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>DemoMavenEclipseProject</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

7) Look at the default folder structure of the Maven project.

EclipseMaven_6

Note: Test cases reside under the src > test > java > PackageName will only be considered as a test by Maven, rest will be ignored if you put your test cases in some other folder.

  1. Modify XML with the latest Junit and save the XML.
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>

Note: In later chapters, we will learn why do we add dependencies and from where we get artifactId & version.

Run your first Maven Test

  1. Right-click on the pom.xml and go to Run As > Maven test.

EclipseMaven_7

  1. In the console window of Eclipse, you would see the information like this:

EclipseMaven_8

  1. Go to ‘SureFire Reports‘ folder and open the XML file.

EclipseMaven_9

  1. It will display the result of the JUnit test.

EclipseMaven_10

How to Create a New Maven Project
How to Create a New Maven Project
Previous Article
Send Reports Automatically to Email using Maven from Eclipse
Send Reports Automatically to Email using Maven from Eclipse
Next Article
Lakshay Sharma
I’M LAKSHAY SHARMA AND I’M FULL STACK TEST AUTOMATION ENGINEER. Have passed 12 years playing with automation in mammoth projects like O2 (UK), Sprint (US), TD Bank (CA), Canadian Tire (CA), NHS (UK) & ASOS(UK). Currently I am working with KNAB bank as SDET. I am passionate about designing Automation Frameworks that follow OOPS concepts and Design patterns. https://www.linkedin.com/in/lakshay-sharma-a4216312/
Reviewers
Virender Singh's Photo
Virender Singh

Similar Articles