SSM(三)公共Common模块的抽离(1)

SSM(二)公共Common模块的抽离

SSM(三)公共Common模块的抽离(1)_第1张图片
在 SSM(二)抽取Parent项目,实现jar包统一管理 文章中,已将普通的maven项目进行抽离,实现了通过parent统一管理Jar包版本,这篇文章将介绍一下如何把公共模块COMMON抽取出来,以便其他模块的复用。

新建子模块W3CJAVA-COMMON

  • 在W3cJavaSSM父项目右键新建Maven Module项目
    SSM(三)公共Common模块的抽离(1)_第2张图片

  • 下一步选择一个quickstart项目即可
    SSM(三)公共Common模块的抽离(1)_第3张图片

  • 调整W3CJAVA-COMMON中pom.xml基本配置(暂时配置


<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">
  <modelVersion>4.0.0modelVersion>
    <parent>
        <artifactId>W3cJavaSSMartifactId>
        <groupId>com.w3cjavagroupId>
        <version>0.0.1-SNAPSHOTversion>
    parent>

    <artifactId>W3CJAVA-COMMONartifactId>
    <packaging>jarpackaging>

project>

以上仅为COMMON模块新建时的基础配置,后面还会根据具体需求来增加配置项。
经过以上处理,项目上可能有红色小叉,这个没什么影响,只要在项目上右键Maven4Myeclipse—Update Project一下即可。

  • 项目结构
    SSM(三)公共Common模块的抽离(1)_第4张图片

公共Jar包抽取到COMMON

  • 将W3CJAVA-WEB下pom.xml中关于Json、Log、单元测试、apache-common相关的依赖剪切到W3CJAVA-COMMON下pom.xml里。

W3CJAVA-COMMON下pom.xml配置:


<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">
  <modelVersion>4.0.0modelVersion>
    <parent>
        <artifactId>W3cJavaSSMartifactId>
        <groupId>com.w3cjavagroupId>
        <version>0.0.1-SNAPSHOTversion>
    parent>

    <artifactId>W3CJAVA-COMMONartifactId>
    <packaging>jarpackaging>
    <dependencies>
        
        <dependency>
            <groupId>junitgroupId>
            <artifactId>junitartifactId>
            <scope>testscope>
        dependency>   
        
        <dependency>
            <groupId>log4jgroupId>
            <artifactId>log4jartifactId>
        dependency>
        
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>fastjsonartifactId>
        dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.coregroupId>
            <artifactId>jackson-annotationsartifactId>
        dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.coregroupId>
            <artifactId>jackson-coreartifactId>
        dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.coregroupId>
            <artifactId>jackson-databindartifactId>
        dependency>
        
        <dependency>
            <groupId>org.apache.commonsgroupId>
            <artifactId>commons-lang3artifactId>
        dependency>               
    dependencies>
project>

W3CJAVA-WEB下pom.xml配置
在pom.xml里已经将COMMON里已有的jar包依赖删除,并且添加了W3CJAVA-COMMON的依赖。因为是WEB项目,所以这里添加了Spring、SpringMVC、Mybatis、sql相关的依赖Jar包。

<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/maven-v4_0_0.xsd">

    <parent>
        <groupId>com.w3cjavagroupId>
        <artifactId>W3cJavaSSMartifactId>
        <version>0.0.1-SNAPSHOTversion>
        <relativePath/> 
    parent>

    <modelVersion>4.0.0modelVersion>
    <artifactId>W3CJAVA-WEBartifactId>
    <packaging>warpackaging>

    <dependencies>
        <dependency>
            <groupId>com.w3cjavagroupId>
            <artifactId>W3CJAVA-COMMONartifactId>
            <version>0.0.1-SNAPSHOTversion>   
        dependency>
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-coreartifactId>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-beansartifactId>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-contextartifactId>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-txartifactId>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webartifactId>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-testartifactId>
            <scope>testscope>
        dependency>
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-webmvcartifactId>
        dependency>
        
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-ormartifactId>
        dependency>
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatis-springartifactId>
        dependency>
        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
        dependency>
        <dependency>
            <groupId>org.mybatisgroupId>
            <artifactId>mybatisartifactId>
        dependency>
        <dependency>
            <groupId>com.alibabagroupId>
            <artifactId>druidartifactId>
        dependency>
        
        <dependency>
            <groupId>org.aspectjgroupId>
            <artifactId>aspectjweaverartifactId>
        dependency>
        

        <dependency>
            <groupId>javax.servletgroupId>
            <artifactId>jstlartifactId>
        dependency>
        
        <dependency>
            <groupId>commons-fileuploadgroupId>
            <artifactId>commons-fileuploadartifactId>
        dependency>
    dependencies>  
project>

parent的pom.xml不作变化,如果需要新增jar包或者插件,将在文章中作说明,那么基本的Jar包抽离到COMMON中算是完成了,稍后将对基础的增删改进行简单的封装。
源码地址:github commo分支

你可能感兴趣的:(SSM)