zoukankan      html  css  js  c++  java
  • 创建分模块的maven项目

    折腾了我2天的maven,整理一下,以后做个参考

    一、什么是maven项目:

      Maven是基于项目对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。

      Maven是跨平台的项目管理工具。主要服务于基于Java平台的项目构建依赖管理项目信息管理

    二、功能:

      1、项目构建

      2、依赖管理

    三、图解步骤:

      1.第一步:创建mavenProject

      

      第二步:项目位置设置,点确定

      第三步:定义父坐标,点finish

     

    第四步:在mavenProject的基础上创建maven Module,在tms_father上右键,new点击Maven Module,创建子工程

    第五步:创建dao层子模块

    第六步:设置dao层子模块信息

     第七步:services,domain,util同理

      

    第八步:创建web层子模块,之前的步骤同上,主要注意红色标注部分

      

     第九步:创建完web层后,会有报错,因为web项目中没有WEB-INF和web.xml文件,操作按下图,操作完成后无报错。

    第十步:打开父节点下的pom.xml,他们的含义如下:

    第十一步:配置pom.xml文件,项目中需要什么就在pom.xml文件中定义什么,pom.xml文件可以管理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/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.cissst</groupId>
      <artifactId>tms_father</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>pom</packaging>
      <description>父项目</description>
      
      <!-- 通过属性定义指定jar的版本 -->
        <properties>
            <spring.version>4.2.4.RELEASE</spring.version>
            <hibernate.version>5.0.7.Final</hibernate.version>
            <struts2.version>2.3.24</struts2.version>
            <slf4j.version>1.6.6</slf4j.version>
            <log4j.version>1.2.12</log4j.version>
            <shiro.version>1.2.3</shiro.version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context-support</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-web</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</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-core</artifactId>
                <version>${spring.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.aspectj</groupId>
                <artifactId>aspectjweaver</artifactId>
                <version>1.7.4</version>
            </dependency>
    
            <!-- struts2 begin -->
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts2-core</artifactId>
                <version>${struts2.version}</version>
                <!-- 排除传递的依赖 -->
                <exclusions>
                    <exclusion>
                        <artifactId>javassist</artifactId>
                        <groupId>javassist</groupId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts2-spring-plugin</artifactId>
                <version>${struts2.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.struts</groupId>
                <artifactId>struts2-convention-plugin</artifactId>
                <version>${struts2.version}</version>
            </dependency>
            <!-- struts2 end -->
    
            <!-- hibernate begin -->
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>${hibernate.version}</version>
            </dependency>
            <!-- hibernate end -->
    
            <!-- log start -->
            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>${log4j.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
    
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <!-- log end -->
    
            <dependency>
                <groupId>org.apache.poi</groupId>
                <artifactId>poi</artifactId>
                <version>3.11</version>
            </dependency>
    
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxws</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http</artifactId>
                <version>3.0.1</version>
            </dependency>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.10</version>
                <scope>test</scope>
            </dependency>
    
            <!-- 加入servlet和jsp的依赖 -->
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
                <version>2.5</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jsp-api</artifactId>
                <version>2.0</version>
                <scope>provided</scope>
            </dependency>
    
            <!-- 引入pinyin4J的依赖 -->
            <dependency>
                <groupId>com.belerweb</groupId>
                <artifactId>pinyin4j</artifactId>
                <version>2.5.0</version>
            </dependency>
            
            <!-- 引入json-lib的依赖 -->
            <dependency>
                <groupId>net.sf.json-lib</groupId>
                <artifactId>json-lib</artifactId>
                <version>2.4</version>
            </dependency>
            
            <!-- 引入c3p0jar包 -->
            <dependency>
                <groupId>c3p0</groupId>
                <artifactId>c3p0</artifactId>
                <version>0.9.1.2</version>
            </dependency>
            
            <!-- 引入ehcache的依赖 -->
            <dependency>
                <groupId>net.sf.ehcache</groupId>
                <artifactId>ehcache-core</artifactId>
                <version>2.6.6</version>
            </dependency>
            <!-- 引入shiro框架的依赖 -->
            <dependency>
                <groupId>org.apache.shiro</groupId>
                <artifactId>shiro-all</artifactId>
                <version>1.2.2</version>
            </dependency>
            <!-- 引入MySQL数据库驱动依赖 -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.32</version>
            </dependency>
        </dependencies>
    
        <build>
            <!-- 插件 -->
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.5</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <!-- 引入tomcat插件 -->
                <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <path>/bos</path>
                        <port>8888</port>
                    </configuration>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>src/main/java</directory>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
                <resource>
                    <directory>src/main/resources</directory>
                    <includes>
                        <include>**/*.properties</include>
                        <include>**/*.xml</include>
                    </includes>
                    <filtering>false</filtering>
                </resource>
            </resources>
        </build>
      
      <modules>
          <module>tms_daos</module>
          <module>tms_services</module>
          <module>tms_util</module>
          <module>tms_domains</module>
          <module>tms_webs</module>
      </modules>
    </project>

    第十二步:十一步倒完后项目可能会有报错,报错提示:Project configuration is not up-to-date with pom.xml. Select: Maven->Update Project... from the project context menu or use Quick Fix,解决方法:项目上,右键---maven---update project,等待一会就ok

      

    第十三步:各个模块之间进行关联

       1.web层pom.xml打开后在pom文档空白处,右键

      2.在打开后搜索依赖的模块

      3.点击ok后,生成如下:

      

    第十四步:其他依赖按照web---service---dao---util---domain(--代表依赖),通过这种方式,可以将被依赖的模块引入当前模块

       1.web模块最终效果:

      

      2.service层效果,其他层类似:

      

    第十五步:至此maven模块搭建完成,开始配置框架配置信息,此处不再细述

     附加:maven中默认的仓库路径为:C:Usersphoebe.m2 epository,也可以指定本地仓库,本地仓库指定方法如下:

      1.下载apache-maven解压后如下所示,打开conf文件夹,配置其中的setting.xml文件。

        

        2.setting.xml文件,指定仓库位置

        

        

        

    Best Regards
  • 相关阅读:
    Eclipse常用插件汇总
    关于销售订单
    java下载文件的种方式
    左右对联
    链表
    Spring MVC 入门
    JAVA环境配置总结
    struts2 iterator判断奇偶
    保存页面的浏览记录
    心扬JS分页
  • 原文地址:https://www.cnblogs.com/pecool/p/8372996.html
Copyright © 2011-2022 走看看