We use simple HelloWorld as an example of getting started, some people say that mastering the HelloWorld you have mastered the half of the technology, for MAVEN, you master HelloWorld, you may still be confused.
1. Create a project from the Maven template
From the command prompt (Windows), browse to the folder where you want to create the Java project. Type the following command:
Project-packaging: Project Package Name
Project-name: Project Name
This tells Maven to create a Java project from the Maven-archetype-quickstart template. If you ignore the Archetypeartifactid option, a huge list of Maven templates will be listed.
For example, here the working directory is E:\workspace_maven, the execution of the command process may be a long time to see the personal network situation.
In the above scenario, a new Java project is named "HelloWorld", and the entire project's directory structure is created automatically.
Attention
A few say the MVN archetype:generate command failed to generate the project structure. If you have any similar problems, don't worry, just skip this step and manually create the folders.
2.Maven Project Catalog Layout
Src/main/java: Used to store source code
Src/main/resources: The resource file used to store the source code
Src/test/java: Used to store unit test code
Src/test/resources: The resource file used to store the test code
3. Use our project in the Eclipse IDE
To make it an Eclipse project, go to the "HelloWorld" project directory and type the following command:
After executing the above command, it automatically downloads updates related resources and configuration information (it will take some time) and produces all the project files required by the Eclipse IDE. To import the project into the Eclipse IDE,
Select File, import ...-general->existing Projects into Workspace, and the Helloword project into eclipse.
Project into the Eclipse IDE,
4. Update the pom file (note: The front section and the following part is a period of time to write, the computer is not the same, so the working space is different, this people know a bit better)
The default pom.xml is too simple, and many times you need to add a compiler plugin to tell Maven which JDK version is used to compile the project, we use the 4.11 version of JUnit and the plugin to indicate which JDK version to use.
5. Run the MAVEN project
Now we will use MAVEN for this project and output the files compiled into a "jar". The package element in the Pom.xml file packaging defines what package should be output.
Back to our project directory, enter the command: MVN package
It compiles, runs unit tests and packages the project into a jar file, and puts it in the Project/target folder.
The directory structure of the final project, such as:
Finally, let's run the jar file and see the results:
Print output: "HelloWorld".
What do you think? is not still confused, it doesn't matter, with the gradual accumulation you will understand what to do.
(iv) New MAVEN project