Create a new Java project in Eclipse. Select File → Java Project or File → New → Other → Java Project. From the dialog window, click the folder for Java and select Java project. Click next and pick a name for your project (JUnitLab). Verify that it’s using JavaSE-16 for the execution environment. Uncheck the module-info.java creation at the bottom.
Click finish. Eclipse may warn you that it needs to open a different perspective. Go ahead and do that.
Now we need to convert it to a Maven project. What is Maven? Maven is a project management tool that is based on POM (project object model). It is used for project build, dependency and documentation. Maven also maximizes our ability to share code without having to download and install jars on the build path. Instead, Maven links to the online repository that holds all of the jars for potential builds and adds the requested one to the build path. This means that multiple users can use the same pom.xml file for their project and easily be able to maintain the project without constantly adding new resources to the build path. Some organizations will use Ivy or Gradle but the concept is still the same.
Now, we need to add Maven as a build manager for our project. To do so, right click on the project and select Configure > Convert to Maven Project. The Create New POM dialog appears, enter the following information:
Note that the Group Id will be used as the main package for our Java code. It will identify your project uniquely across all projects. It has to follow the package name rules. Since we are not deploying these projects on actual functional webservers, this does not matter much for our practice but I want you to be familiar with the naming. e.g. org.apache.maven, com.amazon.cart, edu.school.advancedjava.
The Artifact Id is the name of the jar without version. If you created it then you can choose whatever name you want with lowercase letters and no strange symbols. If it’s a third party jar you have to take the name of the jar as it’s distributed. e.g. maven, commons-math
If we were working with multiple iterations or builds, the Version would update for each change. We won’t see changes in our program, but if you work on a large program, it will be very common for you to update the version along the way (1.0, 1.1, 1.0.1, …).
Add in a name and description and click Finish.
Now you see the pom.xml file created in the project (in the root of the project folder) and it should open up to the Overview page by default.
You may find a red X on the pom.xml. (Your pom.xml might not.) This will be resolved shortly.
One of the first things you should do to make your life easier when working with projects that need additional components is to enable Maven index searching. Trust me: it’s easier to search for dependencies than to type them in (incorrectly).