In this tutorial, you can learn how to use Maven Eclipse plug-in to create, build and package java projects.
Download and install latest version of JDK.
Set JAVA_HOME environment variable to point to the folder where JDK is installed.
Download the latest version of eclipse from eclipse.org.
After downloading the eclipse exe, click it to start eclipse installer.
Choose eclipse IDE for java developers options. In the next window, select folder where you want eclipse to be installed and then click install button.
Then accept terms to start eclipse installation. After installation, start eclipse IDE and select the workspace folder.
By default Maven Eclipse plug-in is installed with eclipse. If it is not installed, go to Help menu, click Eclipse Marketplace, search for Maven and install the plug-in.
Eclipse maven plug-in comes with maven, but if you want to use the latest version of maven, you can configure the plug-in to use different version than the embedded maven runtime. To do that, you need to go to window menu, click preferences, expand maven, click installation and then click add.
New runtime window will be displayed where you need to select maven installation directory that you want to use and click finish.
Then check the newly added maven runtime and click apply.
Similarly, you can import archetype and templates and change user settings.
To create maven project in eclipse, go to file, new and click other.
In the next window, select maven project option.
In the next window, if you want to create the project in different location than eclipse workspace, you can select the location here. Then click next.
In the next window, you can select maven archetype. Since we are going to create simple Java project (jar project), we will select quickstart archetype and then click next.
In the next window, enter group id, artifact id and package and then click finish.
It will create maven jar project with project structure shown in the following image.
If you want to use other jar files in your project, you will have to add them as dependencies in Maven pom.xml. To do that in eclipse, you need to open your project’s pom.xml, click dependencies tab and then click add.
In the select dependencies window, enter group id, artifact id, and version. These details of jar can be obtained from maven central repository web site. After entering dependency details click ok and save pom.
To do a build of the project, right click the project, click run as, select maven build option.
In the edit configuration window, enter maven goals that you want to execute such as clean, compile, test, package, etc. and click run.
After executing package goal, you can find the package, in our case it is a jar, in the target directory. You need to refresh the project if you don’t see it. Following image shows the package and downloaded dependencies after the build.