Build Maven multi-module Project +SSM Framework Integration (i) __maven

Source: Internet
Author: User
Tags aop generator md5 encryption
Maven

Apache Maven is a software project management and comprehension tool.
Based on the concept of a Project object model (POM), Maven can manage
A project ' s build, reporting and documentation from a piece of
Information.

MAVEN is a tool that does not require manual import dependencies, project packaging, and project building
Two key keywords in maven: inheritance and aggregation .
Inheritance: The role is to avoid configuration duplication, for subprojects should be concerned about how the parent project is configured.
Aggregation: The literal understanding is "gathers together completes the work", is gathers the child module to complete the corresponding project demand why should carry on the modular development.

When multiple people are using MAVEN to collaborate on a project, especially on a slightly larger scale, each rd's work is subdivided into specific features and modules, and some modules are even deployed separately.

We assume that there is such a mall project, including the following modules:

Mall Front desk (shop)
Admin background (Admin)
Database interaction Module (DAO)
Common Business Module (service)
Interface Module (API)
General Tools (UTIL)
where shop and admin need to be deployed separately, DAO, service, util you may want some experienced people to maintain, if you use an application to manage, all the functions and modules will be coupled together, everyone can modify the code, this is obviously not what we expect.

And with an application to manage, any one point of code changes, the entire project needs to be build, another advantage of using modular development is that if the DAO's code is modified, it is only necessary to rebuild the DAO module. Web modules can be build into War,dao, service, util, etc. can build into a jar, only need to configure a good dependency, you can achieve the solution coupling between modules. This design is to follow the "high cohesion, low coupling" design principles.
We use the example above to demonstrate that we first make reasonable optimizations, and we want the DAO and service to be used as a common underlying tool, merging them into one core module (CORE), build into Core.jar, and the simple MAVEN modular project structure as follows:

———-Mall//top-level projects
|--pom.xml//packaging = Pom
|--mall-util//Universal Tools
| |-pom.xml//packaging = jar
|--mall-core//CORE modules
| |-pom.xml//packaging = jar
|--MALL-WEB-API//Interface module
| |-pom.xml//packaging = War
|--mall-web-admin//Management Backstage
| |-pom.xml//packaging = War
|--mall-web-shop//Mall Front Desk
| |-pom.xml//packaging = War
The APIs, admin, and shop in these modules are Web applications that can be deployed individually, without dependencies, but all rely on the core module, while the core module relies on the Util module. Next we build the project structure according to the structure we identified above.

Create a project
Using the development tools STS, other tools are similar
(1) New-> Maven project to select where to place the project and tick create a simple project, named study

Note: The parent project will use the Pom method for packaging, there are three default jars, and one is the Web project's War

(2) After the parent project is established, start building the child module new a Maven module

Named Study-dao,parent as study

Select QuickStart

GroupID to be consistent with the parent project, click Finish

Check out Study-dao's pom.xml.

Check out study's pom.xml.

(3) The same way to establish study-service
Just note that the Study-service module needs to introduce Study-dao, and add in the Pom.xml file of the Study-service module
Spring-context also need to use, first add

<dependencies>
        <dependency>
            <groupId>com.study</groupId>
            <artifactid >study-dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactid>junit</artifactid >
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId> spring-context</artifactid>
            <version>4.3.12.RELEASE</version>
        </dependency>

    </dependencies>

(4) To establish the Study-web module ibid. One thing is that he is webapp and needs to be packaged into war

There will be an error when you first set up, it doesn't matter, plus run server can

Take a look at the entire project's directory structure, the overall shelf built up

Study-web pom.xml Adding dependencies, consolidating SSM framework

<?xml version= "1.0"?> <project xsi:schemalocation= "http://maven.apache.org/POM/4.0.0 http:// Maven.apache.org/xsd/maven-4.0.0.xsd "xmlns=" http://maven.apache.org/POM/4.0.0 "xmlns:xsi=" http://www.w3.org/ 2001/xmlschema-instance "> <modelVersion>4.0.0</modelVersion> <parent> <groupId> Com.study</groupid> <artifactId>study</artifactId> <version>0.0.1-snapshot</ver sion> </parent> <groupId>com.study</groupId> &LT;ARTIFACTID&GT;STUDY-WEB&LT;/ARTIFACTID&G
    T <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>study-web Maven W ebapp</name> <url>http://maven.apache.org</url> <properties> <spring.version&gt ;4.3.12.release</spring.version> <servlet.version>3.1.0</servlet.version> <commons-co Dec>1.10</commons-codec> &Lt;mybatis.version>3.4.4</mybatis.version> <mybatis-spring>1.3.0</mybatis-spring> ;c3p0>0.9.5.2</c3p0> <commons-logging>1.1</commons-logging> <mysql-connector-java&
        Gt;5.1.41</mysql-connector-java> <mybatis-generator-core>1.3.2</mybatis-generator-core> <pagehelper>5.0.0</pagehelper> <jackson>2.9.0</jackson> &LT;JSTL&GT;1.2&LT;/JSTL&G
    T </properties> <dependencies> <dependency> <groupid>com.study</groupid&
            Gt <artifactId>study-dao</artifactId> <version>0.0.1-SNAPSHOT</version> </depe ndency> <dependency> <groupId>com.study</groupId> <artifactId>

   Study-service</artifactid> <version>0.0.1-SNAPSHOT</version> </dependency>     <dependency> <groupId>junit</groupId> <artifactid>junit</artifacti d> <version>3.8.1</version> <scope>test</scope> </dependency > <!--servlet-api--> <dependency> &LT;GROUPID&GT;JAVAX.SERVLET&LT;/GROUPID&G
            T
            <artifactId>javax.servlet-api</artifactId> <version>${servlet.version}</version> <scope>provided</scope> </dependency> <!--MD5 encryption--> <dependenc Y> <groupId>commons-codec</groupId> <artifactid>commons-codec</artifactid&
            Gt <version>${commons-codec}</version> </dependency> <!--mybatis--> <de Pendency> <groupId>org.mybatis</groupId> <artifactid>mybatis</artifActid> <version>${mybatis.version}</version> </dependency> <!--mybat Is-spring--> <dependency> <groupId>org.mybatis</groupId> &LT;ARTIFAC Tid>mybatis-spring</artifactid> <version>${mybatis-spring}</version> </depende ncy> <!--spring-core--> <dependency> <groupid>org.springframework</ Groupid> <artifactId>spring-core</artifactId> <version>${spring.version}</ Version> </dependency> <!--spring-context--> <dependency> <
            Groupid>org.springframework</groupid> <artifactId>spring-context</artifactId>
        <version>${spring.version}</version> </dependency> <!--Spring-beans-->
    <dependency>        <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> 
        <version>${spring.version}</version> </dependency> <!--SPRING-AOP--> <dependency> <groupId>org.springframework</groupId> <artifactid>s

        Pring-aop</artifactid> <version>${spring.version}</version> </dependency> <!--spring-aspects--> <dependency> &LT;GROUPID&GT;ORG.SPRINGFRAMEWORK&LT;/GROUPID&G
            T <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> & lt;/dependency> <!--spring-jdbc--> <dependency> <groupid>org.springfram Ework</groupid> <artifactId>spring-jdbc</artifactId> <version>${spring.ver sion}</version> </dependency> <!--spring-tx--> <dependency> <grou Pid>org.springframework</groupid> <artifactId>spring-tx</artifactId> <vers Ion>${spring.version}</version> </dependency> <!--spring-orm--> <depend Ency> <groupId>org.springframework</groupId> <artifactid>spring-orm</artif Actid> <version>${spring.version}</version> </dependency> <!--spring -web--> <dependency> <groupId>org.springframework</groupId> <arti Factid>spring-web</artifactid> <version>${spring.version}</version> </dependen cy> <!--spring-webmvc--> <dependency> <groupId>org.springframework<
           /groupid> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> & Lt;/dependency> <!--Commons logging--> <dependency> <groupid>commons-l Ogging</groupid> <artifactId>commons-logging</artifactId> <version>${commo
            Ns-logging}</version> </dependency> <!--c3p0--> <dependency> <groupId>com.mchange</groupId> <artifactId>c3p0</artifactId> <version 
            >${c3p0}</version> </dependency> <!--mysql-connector--> <dependency>
            <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql-connector-java}</version> </dependency> <!--mybatis gene Rator-->;d ependency> <groupId>org.mybatis.generator</groupId> <artifactid>mybatis-gen Erator-core</artifactid> <version>${mybatis-generator-core}</version> </dependenc y> <!--pagehelper--> <dependency> <groupid>com.github.pagehelper</g Roupid> <artifactId>pagehelper</artifactId> <version>${pagehelper}</versio N> </dependency> <!--Jackson--> <!--<dependency> &LT;GROUPID&GT;COM.FA Sterxml.jackson.core</groupid> <artifactId>jackson-databind</artifactId> <version>2.8 .9</version> </dependency>--> <dependency> <groupid>com.fasterxml.jackso N.core</groupid> <artifactId>jackson-databind</artifactId> <version>${jack
   Son}</version>     </dependency> <!--jstl--> <dependency> <groupid>javax.servle 
         T</groupid> <artifactId>jstl</artifactId> <version>${jstl}</version>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.