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.
- Create java project.
- Import the existing project.
- Create a new project.
- Add dependency.
- Run command.
- 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
- Create a folder C:/WorkSpace/MvnExampleProject.
- Open dos window and run “cd C:/WorkSpace/MvnExampleProject”.
- Run “mvn archetype:generate -DgroupId=com.dev2qa.example.mvn -DartifactId=Dev2qaMavenExample -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false”
- When above command complete, you can see below folder “C:\WorkSpace\MvnExampleProject\Dev2qaMavenExample”.
Import Existing Maven Java Project Into Eclipse
- Open dos window and run “cd C:/WorkSpace/MvnExampleProject/Dev2qaMavenExample”.
- 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.
- Open eclipse, click “File —> Import” menu.
- Choose “Existing Projects Into Workspace” in popup dialog.
- Click “Browse” button to select the below folder C:\WorkSpace\MvnExampleProject\Dev2qaMavenExample
- Click “Finish” button. Now you can see your project in left panel list.
Create A New Maven Project With Eclipse
When you go to Eclipse package list page, you will find that maven has been integrated into it after the Kepler package release.
So you can directly use maven functions if you use above packages.
- Click “File —> New —> Maven Project”.
- Click “Browse” button to choose workspace.
- Click Next, and Select “maven-archetype-quickstart” plugin.
- 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.
- Click “Finish” button, then you will see the new project is listed in left panel.
Add Dependency In Eclipse
- Right click pom.xml, click “Maven —> Add Dependency” in popup menu. You can also do other actions such as add plugin there.
- In the popup dialog you may see “Index downloads are disabled, search results may be incomplete.” warning message as below.
- To resolve this problem, Click “Window —> Preferences”
- Click Maven in left panel, and check below checkbox in right panel.
Download repository index updates on startup,
Download Artifact Sources, Download Artifact JavaDoc
- 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.
- Now return to step2, input testng in search box, then select org.testng:testng dependency.
- Click OK and wait for some time, you can see the dependency updated in pom.xml
Run Command In Eclipse
- Right click pom.xml, click “Run As” menu. You can click to run almost all command in the popup menu.
- You can see the output log in console when click to run one command.
Change Repository In Eclipse
- Click ” Window —> Preferences ” menu.
- 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.