1. 程式人生 > >idea給現有web專案建立子maven web模組專案--搭建流程(以淘淘商城為例)

idea給現有web專案建立子maven web模組專案--搭建流程(以淘淘商城為例)

maven  web專案主要搭建流程:

1、用任意Java開發工具ide中maven外掛(或其他外掛)建立父子web專案骨架

2、完善web專案的目錄結構(如果以下骨架已自動建好,忽略此步驟)  

      src/main/java

      src/main/resources

      src/main/webapp/WEB-INF/web.xml

      src/test/java

      src/test/resources

    (步驟圖第三部分,有圖說明

3、完善配置檔案

      pom.xml:父子及各個模組之間的依賴引用

      web.xml:spring的啟動及頁面跳轉攔截器配置,字元編碼等

      spring相關檔案:註解掃描配置,屬性檔案引用,redis,zookeeper等初始化配置,資料庫引用

      資料庫檔案:資料庫連線,連線池,事物配置

一:新建web專案框架

按步驟進行即可:

 

 

二、建立子模組

1、新增子模組taotao-search-interface

 

 

2、新增子模組taotao-search-service

 

 

 

三:完善專案結構

四:完善配置檔案

1、pom檔案:模組座標、打包方式、專案模組間依賴和對其他jar包的依賴

taotao-search主模組pom.xml檔案

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>taotao-parent</artifactId>
        <groupId>com.taotao</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../taotao-parent/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>taotao-search</artifactId>
    <packaging>pom</packaging>

    <modules>
        <module>taotao-search-interface</module>
        <module>taotao-search-service</module>
    </modules>

    <dependencies>
        <!-- 模組間的依賴 -->
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <!-- dubbo相關 -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>netty</artifactId>
                    <groupId>org.jboss.netty</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <path>/</path>
                    <port>8084</port>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

taotao-search-interface模組pom.xml檔案

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>taotao-search</artifactId>
        <groupId>com.taotao</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>taotao-search-interface</artifactId>

    <dependencies>
        <!-- 模組間的依賴 -->
        <dependency>
            <artifactId>taotao-manager-pojo</artifactId>
            <groupId>com.taotao</groupId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

 taotao-search-service模組pom.xml檔案:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>taotao-content</artifactId>
        <groupId>com.taotao</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>taotao-content-service</artifactId>
    <packaging>war</packaging>

    <dependencies>
        <!-- 模組間的依賴 -->
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-manager-dao</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.taotao</groupId>
            <artifactId>taotao-search-interface</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jms</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <!-- Redis客戶端 -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
        </dependency>
    </dependencies>
</project>

2、spring檔案

根據自己的專案進行spring檔案配置:

3、資料庫檔案

4、web.xml檔案

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         id="WebApp_ID" version="2.5">
  <display-name>taotao-search</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

  <!-- 初始化spring容器 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:spring/applicationContext-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
</web-app>