Import Maven web project in eclipse and configure it to run in Tomcat

Today, due to the internship, we need to import the company's developed projects into eclipse, and the company's projects are built with Maven. Therefore, we need to import Maven projects into eclipse.

Because I have no experience, I spent more than two hours. I'm here to share my experience and some problems I have encountered in this process.

First, I checked out the company's project locally through SVN.

Because Maven follows the principle that specification is more important than configuration, the structure of Maven project is generally a POM after entering the directory XML file and a SRC folder, of course, there may be some readme and so on, which are not important. The most important thing is POM XML and Src folders. Under SRC, Src / main / Java is generally the source code of the project, and under Src / test / Java is the test code.

Open eclipse. Of course, before importing, make sure you have installed Maven and added Maven's plug-in to eclipse.

After making sure that the above installation has been carried out, click "file - > Import - > Maven" in eclipse

Then select existing Maven projects, and then select the folder where the project you want to import is located

Select the corresponding item of the project you want to import. Click Finish to import the project.

After that, the work to be done is to convert the Maven project into a dynamic web module, right-click the project, select the properties of the last item in the menu, and select from the list on the left

project facets,

Select "dynamic web module" and click "further configuration available.." below

Context root is the name of your project. Set the content directory to Src / main / webapp and click OK

Then click OK, and the project will be converted to a web project

Continue to right-click the project, select properties, and select the deployment assembly option,

There is also a test related item in the company's project, which can be deleted because it is not used during deployment, and then add a dependent library for the project,

Click Add and select Java build path entries,

Select Maven dependencies so that Maven will automatically download the dependency library at the first run when the project runs.

Click finish and the whole project will be transformed into a running web project.

Then create a new web server, which requires Tomcat to be installed and integrated into eclipse, so that the web server can be created. After creating the web server, right-click the project we imported

Select run on server from run as

This completes the entire configuration.

There may be errors when you run again. If it is a company project, this is very likely. There may be some conflicts because there are many dependent libraries. The conflicts I have here are the conflicts between the Tomcat related libraries in the dependent libraries downloaded by Maven and the libraries in our local Tomcat server, Just delete these jar packages in the Lib directory of the current project

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>