On your computer, open the command line. Navigate to the location where you want to create a new project and type the following command:
You will get a huge list, suggesting what types of projects you can create. A suggestion is made for you at the command line cursor (near the text 'Choose a number or apply filter'). Type in the suggested number. This will generate a 'maven-archetype-quickstart' type of project. This will generate a very basic project for you to work with. Next, you will be asked for this type of project's version. Type in the suggested number. Next you need to enter the groupID. This information will uniquely identify your project, and it must follow the naming conventions that Java developers adhere to: http://docs.oracle.com/javase/specs/jls/se7/html/jls-6.html#d5e6484 . For the purpose of this tutorial, i will create the following groupID: 'com.i.am.a.little.tester'.
For the artifactID, enter the name for your project. For this tutorial, i will create the following artifactID: 'testproject'.
For the version property, enter the following information: '1.0-SNAPSHOT'.
For package just enter 'jar'.
After this, you will get a confirmation screen. Type 'Y' to confirm the information you just typed in. You will get a 'Build Success' screen, which means the project compiled and the project's files are properly structured inside folders and packages.
The next step is to import the generated project into your IDE. It needs to be imported as a Maven project. The information on how to import the Maven project can be found here: for Intellij - http://wiki.jetbrains.net/intellij/Creating_and_importing_Maven_projects and for Eclipse - http://stackoverflow.com/questions/2061094/importing-maven-project-into-eclipse . By examining the project structure, you will have the following folders (screenshot is generated by Intellij, so the .idea folder and the .iml file are specific to this IDE).
Notice you now have the two folder structures: src/main/java and src/test/java. The developer's code will be places within the 'main' folder, the tests will be placed within the 'test' folder. After successfully importing the project into the IDE, open the pom.xml file. Edit the file, so that you are only left with the following information in the file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>your.group.id</groupId> <artifactId>yourproject</artifactId> <version>1.0-SNAPSHOT</version> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> </dependencies> </project>
Also, delete any file or folder that might appear in the following location within your project: src/main/java and src/test/java. These are default files generated by Maven for the specific project type you chose at the 'generate archetype' step (because you chose 'jar' for the 'package' parameter when you generated the project, you will have a 'jar' folder inside the two folders mentioned above, each folder containing a class, that you won't need in your tests). Now, from the command line, browse to your project's location. Type the following command:
mvn clean install
This command should now return a 'Build Success' message. This means the project has successfully compiled and it is ready to be setup for your testing needs. The next step is to import the testing dependencies, which you will learn how to do here: https://imalittletester.com/2014/02/20/import-the-testing-dependencies/. For more information on what the pom.xml file is, you can read this documentation from Maven: https://maven.apache.org/guides/introduction/introduction-to-the-pom.html.