A method of transforming a common web project developed in Java into a maven project

preface

Maven is based on the project object model (project object model), a project management tool that can manage project construction, reports and documents through a short section of description information, provides the concept of a warehouse, and uniformly manages the third-party jar packages that the project depends on, so as to avoid the problem that it cannot run between different computers due to different environment variables. Struts 2 and Hibernate are deployed using Maven Purpose.

Now there are many blog posts on the Internet that convert ordinary web projects into Maven projects, but due to different projects, the required steps and necessary conversion steps are also different. Therefore, this article will take a mall project based on spring MVC, spring and Hibernate as an example to detail the transformation process.

Specific examples

explain

objective

Convert a normal dynamic web project to a maven project

step

premise

Before the conversion, put the project on GitHub and clone it to the idea to prevent the project bug from being difficult to remedy due to the final failure. After all, the revision function of Git is great!!

1. Convert the project into Maven project

Select Add framework support and check import Maven dependency

2. Back up lib, remove lib, and write POM xml

Don't worry when you see a large "red" below. It's only the first step to "subvert the world". You must not shrink back

Then back up the lib, remove the Lib of the project, and put the project in the "empty jar" state

Supplement POM The header of XML is automatically generated, and several necessary configurations will be omitted

Then there is individual effort. Enter each Java, properties, XML, JSP and other files and use the add Maven dependency method to automatically import them (shortcut key: Alt + Enter). Of course, the premise is that the network speed is better!

After the previous step, most of the necessary dependencies have been initially imported. Then, import some other dependencies (refer to the previously backed up LIB). Don't ignore this step, because these dependencies such as MySQL connector java have not been imported!

3. Cut the spring configuration file, database property file and log configuration file under Src / main / resources

If there is an error in the mapping path of the configuration file, remember to enter and correct it. Most incorrect paths can be tested by CMD + mouse under idea.

4. Cut the files (including JS, CSS, JSP, etc.) originally placed under the Webroot path to the webapp folder, and delete the Webroot folder

What matters is the WEB-INF folder

5. Redeploy and test

Redeploy to Tomcat (or jetty) to test the effect.

Basically, this step is not far from success (and I have succeeded). If... If there are still bugs, adjust more, look at the log and console output until the conversion is successful. It is also a great attempt.

summary

Maven is a very good software project management tool, so many program apes may frequently encounter the conversion of dynamic web projects to Maven projects. At this time, you can learn it for emergencies! Encourage each other!!

Well, the above is the whole content of this article. I hope the content of this article has a certain reference value for your study or work. If you have any questions, you can leave a message. Thank you for your support for programming tips.

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
分享
二维码
< <上一篇
下一篇>>