Manage Maven Project Using Eclipse

Maven java project can be created and maintained in command line. If you do not know how to achieve that, you can read  How To Create Java Project With Maven,  How To Use Maven To Build And Run Java Project.  But it is more effective to use Java IDE such as Eclipse to manage it. In this article you can learn below maven tasks processed within eclipse.

  1. Create java project.
  2. Import the existing project.
  3. Create a new project.
  4. Add dependency.
  5. Run command.
  6. Change repository.

Eclipse is the most popular Java IDE that can be used to easily edit, debug, compile and package java project. But how can we use it with our maven java project then can make management to be more easily?

Create A Maven Project

  1. Create a folder C:/WorkSpace/MvnExampleProject.
  2. Open dos window and run “cd C:/WorkSpace/MvnExampleProject”.
  3. Run “mvn archetype:generate -DgroupId=com.dev2qa.example.mvn -DartifactId=Dev2qaMavenExample -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false”
  4. When above command complete, you can see below folder “C:WorkSpaceMvnExampleProjectDev2qaMavenExample”.
    Manage Maven Project Using Eclipse

Import Existing Maven Java Project Into Eclipse

  1. Open dos window and run “cd C:/WorkSpace/MvnExampleProject/Dev2qaMavenExample”.
  2. Run “mvn eclipse:eclipse” command to add needed project files into it. This command will download a lot of plugin jar files and save them into your local repository.
    It will also generate all the project files that needed when import into eclipse.
    Manage Maven Project Using Eclipse
  3. Open eclipse, click “File —> Import” menu.
    Manage Maven Project Using Eclipse
  4. Choose “Existing Projects Into Workspace” in popup dialog.
    Manage Maven Project Using Eclipse
  5. Click “Browse” button to select the below folder C:WorkSpaceMvnExampleProjectDev2qaMavenExample
    Manage Maven Project Using Eclipse
  6. Click “Finish” button. Now you can see your project in left panel list.
    Manage Maven Project Using Eclipse

Create A New Maven Project With Eclipse

When you go to READ :   Create Java Project With Maven

Manage Maven Project Using Eclipse

So you can directly use maven functions if you use above packages.

  1. Click “File —> New —> Maven Project”.
    Manage Maven Project Using Eclipse
  2. Click “Browse” button to choose workspace.
    Manage Maven Project Using Eclipse
  3. Click Next, and Select “maven-archetype-quickstart” plugin.
    Manage Maven Project Using Eclipse
  4. Click Next, input group id, artifact id and package name in the next dialog. The artifact id will be used as the project name. And you can edit artifact id and package name separately.
    Manage Maven Project Using Eclipse
  5. Click “Finish” button, then you will see the new project is listed in left panel.
    Manage Maven Project Using Eclipse

Add Dependency In Eclipse

  1. Right click pom.xml, click “Maven —> Add Dependency” in popup menu. You can also do other actions such as add plugin there.
    Manage Maven Project Using Eclipse
  2. In the popup dialog you may see “Index downloads are disabled, search results may be incomplete.” warning message as below.
    Manage Maven Project Using Eclipse
  3. To resolve this problem, Click “Window —> Preferences”
    Manage Maven Project Using Eclipse
  4. Click Maven in left panel, and check below checkbox in right panel.
    Download repository index updates on startup,
    Download Artifact Sources, Download Artifact JavaDoc
    Manage Maven Project Using Eclipse
  5. Click OK, and restart eclipse. After restart, you may see a progress bar in bottom, that is just the process of repository index updates. This will take some minutes.
    Manage Maven Project Using Eclipse
  6. Now return to step2, input testng in search box, then select org.testng:testng dependency.
    Manage Maven Project Using Eclipse
  7. Click OK and wait for some time, you can see the dependency updated in pom.xml
    Manage Maven Project Using Eclipse

Run Command In Eclipse

  1. Right click pom.xml, click “Run As” menu. You can click to run almost all command in the popup menu.
    Manage Maven Project Using Eclipse
  2. You can see the output log in console when click to run one command.
    Manage Maven Project Using Eclipse
READ :   How To Deploy A Maven Project To Tomcat From Eclipse

Change Repository In Eclipse

  1. Click ” Window —> Preferences ” menu.
    Manage Maven Project Using Eclipse
  2. Click “Maven —> User Settings” in left panel. Click “Browse” button in right panel to select your local installed maven configure settings.xml file. Click “Reindex” button.
    Manage Maven Project Using Eclipse
  • 0