Preface
Maven is a project management tool that can manage project construction, reports and documents through a small piece of descriptive information. It provides a warehouse concept and unified management of third-party jar packages that projects rely on, which can avoid the problem that cannot run between different computers due to different environment variables. Struts2 and Hibernate are both projects deployed using maven.
There are many blog posts on the Internet that convert ordinary web projects to 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 SpringMVC, Spring, Hibernate as an example to describe the conversion process in detail.
Specific examples
illustrate
Purpose
Convert a normal Dynamic Web Project to a Maven Project
step
premise
Before the conversion, place the project on Github and clone it on IDEA to prevent the project bugs from being difficult to remediate if it fails in the end. After all, git's revision function is quite great! !
1. Convert the project to a Maven project
Select Add framework support and check Import "Maven" dependency
2. Back up lib and then remove lib, and then write pom.xml
Don't worry when you see a large piece of "red" below, that's just your first step to "subvert the world". Never retreat.
Then back up the lib, then remove the project's lib, and put the project in the "empty jar" state
Add pom.xml header, and the automatically generated will omit several necessary configurations
<modelVersion>4.0.0</modelVersion> <groupId>com.shop</groupId> <artifactId>Shop</artifactId> <packaging>war</packaging> <version>1.0-SNAPSHOT</version> <name>Shop Maven Webapp</name> <url>http://maven.apache.org</url>
Next is a physical job, enter each java, properties, xml, jsp and other files automatically import using Add Maven dependency method (shortcut key: alt+enter), of course, the premise is that the Internet speed must be good!
After the previous step, most of the necessary dependencies have been imported initially. Then, some other dependencies (refer to the lib backed up before) are imported. Don’t ignore this step, because dependencies such as mysql-connector-java are generally not imported yet!
3. Cut spring configuration files, database attribute files, log configuration files, etc. into src/main/resources
If there is any error in the mapping path of the configuration file inside, remember to enter the correction. The cmd+mouse under idea can test most incorrect paths.
4. Cut the files (including js, css, jss, etc.) that were originally placed in 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, at this point, it is not far from success (and I have already succeeded). If...if there are still bugs, adjust the tune more, look at the logs, and look at the console output. It is also a great attempt until the conversion is successful.
Summarize
Maven is a very good software project management tool, so many programmers may frequently encounter the situation where Dynamic Web projects are converted to Maven projects. At this time, everyone can learn to prepare for emergencies! mutual encouragement! !
Okay, the above is the entire content of this article. I hope that the content of this article has certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support to Wulin.com.