Creating the project
Select the menu: File > New > Other:
Type “Maven” in the “Wizards” input and select the option “Maven Project”:
Check the option “Create a simple Project (skip archetype selection)” and press “Next”:
A folder structure like below will be created.
When we work with Maven this is the folder structure that it uses. In the “Java Resources” we will have folder with the Java classes that will go to the production environment with the project configurations. In the “src/main/java” will be located the java classes and in the “src/main/resources” will be located the configurations files. The “src/test/*” folder it is place that we can create the test classes and the tests configurations. This project will not have any automated test because it is just a CRUD, but it is always good to have tests for your projects.
“src/main/webapp” it is like the ROOT of the “WAR” file. Everything inside this folder will be placed in the ROOT of the created artifact; the WEB-INF and XML configurations file will be found inside this folder. It has the same function of the Eclipse “WebContent” folder when we use a “Dynamic Web Project”.
The “target” folder is where the created “WAR” artifact and compiled files are. This folder should not be saved in the SVN or your repository. All this folder content is created every time that the code is compiled; there is no need to save this folder. When we use Maven it is usual to find full projects with 1MB of size, because the libraries are added only to the generated artifact and not to the source code. In this project we will use a Tomcat plugin that the Maven will manage, making easier the project deploy (we will see more about it later in this post).
Maven is a framework responsible to manage all the dependencies and packing the classes with other libraries. e.g: to change a library version it will be easier to edit the “pom.xml” file and change the library version just writing 3.0.0 (when 2.3.4 was the version), than search all over the internet for a specific version to download and manually add it to the project.
Maven is a powerful tool, and to those that want to understand better how it works there is this book: Maven: ‘The Definitive Guide – Sonatype Company’.
Solving the JDK Build Path problem
After creating the project, if the error message below appear, it will be necessary to edit the project “Build Path”:
To edit the JDK just right mouse click on the project > Properties:
In the menu “Java Build Path” select the “Libraries” tab, check the item “JRE Systm Library [XXX]” and then select the “Edit” button:
A dialog will be displayed with JRE option displayed in the SO. I usually check the option “Workspace default JRE (XXX)”.
The displayed label in “Workspace default” may vary, because it depends of the installed JDK version of your machine. You must have, at least, the JDK 6 installed in your PC.