How to install Maven in Eclipse

By: Slav Kurochkin

Once you got Maven on your computer (How to install Maven on your computer), you probably want to install Maven plugin in Eclipse:
- Open Eclipse
- Open “Help” in menu bar
- Select “Install New Software”

- Click “Add” button
- type “Maven” in Name field
- paste to Location: http://download.eclipse.org/technology/m2e/releases/

- tap “ok” button
- once “Maven Integration for Eclipse” appear select it and click “Next” button

Maven installed now you should be able to use Maven in your project, you need add pom.xml file and add dependencies

- right click on Eclipse project
- New
- File

- type pom.xml and then save your file

Now you need add some dependency to your pom.xml, it is depend on the project how exactly it will look like, mine for mobile testing is looking like that, I basically copied it from Appium Java-Client git repository:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

   <groupId>com.saloote</groupId>
    <artifactId>java-test</artifactId>
    <version>1.0.1</version>

    <dependencies>    
    <dependency>
      <groupId>org.testng</groupId>
      <artifactId>testng</artifactId>
      <version>6.3.1</version>
      <scope>test</scope>
    </dependency>
    
    
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.2.4</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.42.2</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.3.3</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>17.0</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>3.1</version>
        </dependency>



        <dependency>
        	<groupId>io.appium</groupId>
        	<artifactId>java-client</artifactId>
        	<version>1.6.0</version>
        </dependency>
    </dependencies>
    <packaging>jar</packaging>
    <name>java-client</name>
    <description>Java client for Appium Mobile Webdriver</description>
    <url>http://appium.io</url>

    <licenses>
        <license>
            <name>Apache License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url>https://github.com/appium/java-client</url>
        <connection>scm:git:git://github.com/appium/java-client.git</connection>
        <developerConnection>scm:git:git@github.com:appium/java-client.git</developerConnection>
    </scm>

    <developers>
        <developer>
            <email></email>
            <name></name>
            <url>https://github.com/jonahss</url>
            <id></id>
        </developer>
    </developers>

    <distributionManagement>
        <snapshotRepository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>ossrh</id>
            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
        </repository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>2.2.1</version>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar-no-fork</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-javadoc-plugin</artifactId>
                <version>2.9.1</version>
                <executions>
                    <execution>
                        <id>attach-javadocs</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-gpg-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <id>sign-artifacts</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>sign</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
View Comments

Leave a Comment

Use markdown or basic HTML and be nice.