maven多项目配置(maven-分布式项目之工程结构配置)
maven的作用
1.管理jar包及依赖、工程之间的依赖
2.项目构建。
3.工程聚合、继承、依赖
Maven的工程类型
1.war包工程
2.Jar包工程
3.pom工程
后台管理系统工程结构:
taotao-parent (pom)-- 管理依赖jar包的版本,全局,公司级别
|--taotao-common (jar)--- 通用组件、工具类
|--taotao-manage (pom)-- 后台系统
|--com.taotao.manage.web(war)
|--com.taotao.manage.service(jar)
|--com.taotao.manage.mapper(jar)
|--com.taotao.manage.pojo(jar)
1.创建taotao-parent父工程
1.new a maven project
2.Create a simple project
3.Packaging选择pom(聚合项目)
4.修改pom.xml
[html] view plain copy
- <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.taotao</groupId>
- <artifactId>taotao-parent</artifactId>
- <version>0.0.1-SNAPSHOT</version>
- <packaging>pom</packaging>
- <!-- 集中定义依赖版本号 -->
- <properties>
- <junit.version>4.12</junit.version>
- <spring.version>4.1.3.RELEASE</spring.version>
- <mybatis.version>3.2.8</mybatis.version>
- <mybatis.spring.version>1.2.2</mybatis.spring.version>
- <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
- <mysql.version>5.1.32</mysql.version>
- <slf4j.version>1.6.4</slf4j.version>
- <jackson.version>2.4.2</jackson.version>
- <druid.version>1.0.9</druid.version>
- <httpclient.version>4.3.5</httpclient.version>
- <jstl.version>1.2</jstl.version>
- <servlet-api.version>2.5</servlet-api.version>
- <jsp-api.version>2.0</jsp-api.version>
- <joda-time.version>2.5</joda-time.version>
- <commons-lang3.version>3.3.2</commons-lang3.version>
- <commons-io.version>1.3.2</commons-io.version>
- <commons-net.version>3.3</commons-net.version>
- <pagehelper.version>3.4.2-fix</pagehelper.version>
- <jsqlparser.version>0.9.1</jsqlparser.version>
- <commons-fileupload.version>1.3.1</commons-fileupload.version>
- <jedis.version>2.7.2</jedis.version>
- <solrj.version>4.10.3</solrj.version>
- </properties>
- <dependencyManagement>
- <dependencies>
- <!-- 时间操作组件 -->
- <dependency>
- <groupId>joda-time</groupId>
- <artifactId>joda-time</artifactId>
- <version>${joda-time.version}</version>
- </dependency>
- <!-- Apache工具组件 -->
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-lang3</artifactId>
- <version>${commons-lang3.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.commons</groupId>
- <artifactId>commons-io</artifactId>
- <version>${commons-io.version}</version>
- </dependency>
- <dependency>
- <groupId>commons-net</groupId>
- <artifactId>commons-net</artifactId>
- <version>${commons-net.version}</version>
- </dependency>
- <!-- Jackson Json处理工具包 -->
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>${jackson.version}</version>
- </dependency>
- <!-- httpclient -->
- <dependency>
- <groupId>org.apache.httpcomponents</groupId>
- <artifactId>httpclient</artifactId>
- <version>${httpclient.version}</version>
- </dependency>
- <!-- 单元测试 -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>${junit.version}</version>
- <scope>test</scope>
- </dependency>
- <!-- 日志处理 -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${slf4j.version}</version>
- </dependency>
- <!-- Mybatis -->
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis</artifactId>
- <version>${mybatis.version}</version>
- </dependency>
- <dependency>
- <groupId>org.mybatis</groupId>
- <artifactId>mybatis-spring</artifactId>
- <version>${mybatis.spring.version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.miemiedev</groupId>
- <artifactId>mybatis-paginator</artifactId>
- <version>${mybatis.paginator.version}</version>
- </dependency>
- <dependency>
- <groupId>com.github.pagehelper</groupId>
- <artifactId>pagehelper</artifactId>
- <version>${pagehelper.version}</version>
- </dependency>
- <!-- MySql -->
- <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>${mysql.version}</version>
- </dependency>
- <!-- 连接池 -->
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid</artifactId>
- <version>${druid.version}</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>
- <!-- JSP相关 -->
- <dependency>
- <groupId>jstl</groupId>
- <artifactId>jstl</artifactId>
- <version>${jstl.version}</version>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <version>${servlet-api.version}</version>
- <scope>provided</scope>
- </dependency>
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>jsp-api</artifactId>
- <version>${jsp-api.version}</version>
- <scope>provided</scope>
- </dependency>
- <!-- 文件上传组件 -->
- <dependency>
- <groupId>commons-fileupload</groupId>
- <artifactId>commons-fileupload</artifactId>
- <version>${commons-fileupload.version}</version>
- </dependency>
- <!-- Redis客户端 -->
- <dependency>
- <groupId>redis.clients</groupId>
- <artifactId>jedis</artifactId>
- <version>${jedis.version}</version>
- </dependency>
- <!-- solr客户端 -->
- <dependency>
- <groupId>org.apache.solr</groupId>
- <artifactId>solr-solrj</artifactId>
- <version>${solrj.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
- <build>
- <finalName>${project.artifactId}</finalName>
- <plugins>
- <!-- 资源文件拷贝插件 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>2.7</version>
- <configuration>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- <!-- java编译插件 -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <encoding>UTF-8</encoding>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <!-- 配置Tomcat插件 -->
- <plugin>
- <groupId>org.apache.tomcat.maven</groupId>
- <artifactId>tomcat7-maven-plugin</artifactId>
- <version>2.2</version>
- <configuration>
- <path>/</path>
- <port>8888</port>
- <charset>utf-8</charset>
- <uriEncoding>UTF-8</uriEncoding>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
- </project>
5.maven install 打包到本地仓库
4.创建taotao-manager-pojo模块
1.右键taotao-manager---new Maven Module
2.Create a simple project
3.Packaging选择jar(被其他工程所引用)
4.Group id与taotao-parent的Group id一致(同一组织)
5.pom文件不需要修改,不依赖任何jar包
5.创建taotao-manager-mapper
1.右键taotao-manager---new Maven Module
2.Create a simple project
3.Packaging选择jar(被其他工程所引用)
4.Group id与taotao-parent的Group id一致(同一组织)
5.pom文件修改(依赖taotao-manager-pojo)。及添加mybatis、分页插件、数据库连接池、mysql连接依赖
6.创建taotao-manager-service
1.右键taotao-manager---new Maven Module
2.Create a simple project
3.Packaging选择jar(被其他工程所引用)
4.Group id与taotao-parent的Group id一致(同一组织)
5.pom文件修改(依赖taotao-manager-mapper)。及添加spring相关依赖
7.创建taotao-manager-web
1.右键taotao-manager---new Maven Module
2.Create a simple project
3.Packaging选择war
4.Group id与taotao-parent的Group id一致(同一组织)
5.pom文件修改(依赖taotao-manager-service)。及添加jstl、jsp、servlet、commons-fileupload等依赖
6.在webapp下创建WEB-INF,继续创建web.xml
[html] view plain copy
- <?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
- id="taotao" version="2.5">
- <display-name>taotao-manager</display-name>
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- <welcome-file>index.htm</welcome-file>
- <welcome-file>index.jsp</welcome-file>
- <welcome-file>default.html</welcome-file>
- <welcome-file>default.htm</welcome-file>
- <welcome-file>default.jsp</welcome-file>
- </welcome-file-list>
- </web-app>
要运行工程,需要运行聚合工程也就是taotao-manager。
1.在taotao-manager工程的pom文件中添加如下内容:
[html] view plain copy
- <build>
- <!-- 配置插件 -->
- <plugins>
- <plugin>
- <groupId>org.apache.tomcat.maven</groupId>
- <artifactId>tomcat7-maven-plugin</artifactId>
- <configuration>
- <port>8080</port>
- <path>/</path>
- </configuration>
- </plugin>
- </plugins>
- </build>
2.使用maven命令:
clean tomcat7:run
注意:
(1)需要把taotao-parent工程安装到本地仓库。Install
(2)需要把taotao-common安装到本地仓库。
,免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com