Recently, I encountered a Spring MVC project managed by Maven. A person in the group threw the project code over and looked confused (). After checking some information, he finally ran the project (>_<). I will record it and share it with you.
In layman's terms, Maven is a project management tool similar to git. Spring MVC separates M (Model), V (View), and C (Controller) and processes it, which is more conducive to development. Below I will introduce how to import a Maven project that someone has compiled and thrown to you.
Development environment: Eclipse
Step1:
In Eclipse, select File->Import; then the following figure is shown:
Click Browse, select the folder where the project is located, and then Finish to add the project.
Step2:
Convert the imported Maven project into a Dynamic Web Module and check the red box in the following figure;
Step3: Add Maven Dependencies
Continue to right-click the project ->properties->Deployment Assembly, as shown in the red box in the figure, there are only four folders under src:
Click Add as shown in the figure:
From the above 3 steps, the imported Maven project will be converted into a runnable web project.
Then create a new Web Server. This requires Tomcat to be installed and integrated into Eclipse. This way, you can create a Web Server. After creating the Web Server, right-click the project we imported, select "Run As", and select Run on Server. Right-click the project->run on server.
Tips:
(1) Your own development environment Eclipse must be configured correctly with Tomcat, and the version of Tomcat should be consistent with the previous version.
(2) If you run Run on Server, Tomcat starts the console and reports an error: "Critical Error: Java lang.ClassNotFound" (I can't remember it, it should be like this), which means that your Maven Dependencies have not been added.
Eclipse maven imports parent and child modules
Many times a large maven module contains many small maven modules. At this time, it will be more troublesome if we first import the large maven module and then import its submodules one by one. Here is a method to quickly import all maven modules.
1. Import the main maven module
2. Delete the project from Eclipse, but do not choose to delete from hard disk.
3. Re-import the deleted module through the local project
In this way, Maven will automatically download all other submodules contained in the parent module according to the module's dependencies.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.