(五)构建dubbo分布式平台-maven构建根项目

上一篇我们介绍《构建dubbo分布式平台-maven代码结构》,从今天开始,我们将对代码的每一个构建做详细的记录,能够帮助大家如何快速构建dubbo分布式企业架构。

导语:在dubbo分布式架构构建之前,请大家务必掌握maven的相关技能,因为架构中大量使用maven技术进行项目构建,有不熟的朋友可以在网上找一些资料学习。

1. 准备技能

开发语言:JAVA/J2EE

项目构建管理:Maven

持续集成方案:Jenkins

SOA服务: Dubbo、zookeeper、Restful

SSO单点登录:Redis、JWT、Restful

分布式缓存:Redis

分布式消息中间件:zookeeper+kafka

分布式文件:FastDFS

数据库连接池:Alibaba Druid

核心框架:Spring framework、Spring MVC、Apache Shiro、MyBatis

前端框架:Bootstrap + html5 + CSS3

2. 创建maven基础项目,其中只需要配置pom.xml文件和打包的文件即可,代码如下:

[html]  view plain  copy
  1. <span style="font-size: 16px;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <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">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.   
  5.     <groupId>com.sml.sz</groupId>  
  6.     <artifactId>ant-project</artifactId>  
  7.     <version>1.0.0</version>  
  8.     <packaging>pom</packaging>  
  9.   
  10.     <name>ant-project</name>  
  11.     <url>http://maven.apache.org</url>  
  12.     <inceptionYear>2015-2016</inceptionYear>  
  13.   
  14.     <properties>  
  15.         <!-- 框架通用包版本设置 -->  
  16.         <spring.version>4.2.2.RELEASE</spring.version>  
  17.         <validator.version>5.1.1.Final</validator.version>  
  18.         <mybatis.version>3.2.8</mybatis.version>  
  19.         <mybatis-spring.version>1.2.2</mybatis-spring.version>  
  20.         <shiro.version>1.2.3</shiro.version>  
  21.         <druid.version>1.0.11</druid.version>  
  22.         <ehcache.version>2.6.9</ehcache.version>  
  23.         <ehcache-web.version>2.0.4</ehcache-web.version>  
  24.         <sitemesh.version>2.4.2</sitemesh.version>  
  25.         <activiti.version>5.15.1</activiti.version>  
  26.         <wink.version>1.4</wink.version>  
  27.         <sso.client.version>3.2.1</sso.client.version>  
  28.   
  29.         <!-- 通用工具包版本设置 -->  
  30.         <slf4j.version>1.7.7</slf4j.version>  
  31.         <commons-lang3.version>3.3.2</commons-lang3.version>  
  32.         <commons-io.version>2.4</commons-io.version>  
  33.         <commons-codec.version>1.9</commons-codec.version>  
  34.         <commons-fileupload.version>1.3.1</commons-fileupload.version>  
  35.         <commons-beanutils.version>1.9.1</commons-beanutils.version>  
  36.         <jackson.version>2.2.3</jackson.version>  
  37.         <fastjson.version>1.1.40</fastjson.version>  
  38.         <xstream.version>1.4.7</xstream.version>  
  39.         <guava.version>17.0</guava.version>  
  40.         <dozer.version>5.5.1</dozer.version>  
  41.         <email.version>1.4.7</email.version>  
  42.         <poi.version>3.9</poi.version>  
  43.         <freemarker.version>2.3.20</freemarker.version>  
  44.   
  45.         <!-- 基础环境设置 -->  
  46.         <jdk.version>1.6</jdk.version>  
  47.         <tomcat.version>2.2</tomcat.version>  
  48.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>  
  49.         <downloadSources>true</downloadSources>  
  50.   
  51.         <!-- jdbc驱动版本设置 -->  
  52.         <mysql.driver.version>5.1.30</mysql.driver.version>  
  53.     </properties>  
  54.   
  55.     <dependencies>  
  56.         <!-- 单元测试 -->  
  57.         <dependency>  
  58.             <groupId>junit</groupId>  
  59.             <artifactId>junit</artifactId>  
  60.             <version>4.11</version>  
  61.             <scope>test</scope>  
  62.         </dependency>  
  63.         <!-- Tomcat 如果存在就不需要将servlet-api.jar、jsp-api.jar一起打包 -->  
  64.         <dependency>  
  65.             <groupId>javax.servlet</groupId>  
  66.             <artifactId>servlet-api</artifactId>  
  67.             <version>2.5</version>  
  68.             <scope>provided</scope>  
  69.         </dependency>  
  70.         <dependency>  
  71.             <groupId>javax.servlet.jsp</groupId>  
  72.             <artifactId>jsp-api</artifactId>  
  73.             <version>2.1</version>  
  74.             <scope>provided</scope>  
  75.         </dependency>  
  76.     </dependencies>  
  77.   
  78.     <dependencyManagement>  
  79.         <dependencies>  
  80.             <!-- ant 工具jar -->  
  81.             <dependency>  
  82.                 <groupId>com.sml.sz</groupId>  
  83.                 <artifactId>ant-utils</artifactId>  
  84.                 <version>${project.version}</version>  
  85.             </dependency>  
  86.             <!-- ant 公共配置jar -->  
  87.             <dependency>  
  88.                 <groupId>com.sml.sz</groupId>  
  89.                 <artifactId>ant-config</artifactId>  
  90.                 <version>${project.version}</version>  
  91.             </dependency>  
  92.             <!-- ant 核心框架jar -->  
  93.             <dependency>  
  94.                 <groupId>com.sml.sz</groupId>  
  95.                 <artifactId>ant-framework</artifactId>  
  96.                 <version>${project.version}</version>  
  97.             </dependency>  
  98.             <!-- ant 代码自动生成业务jar -->  
  99.             <dependency>  
  100.                 <groupId>com.sml.sz</groupId>  
  101.                 <artifactId>ant-core-gen</artifactId>  
  102.                 <version>${project.version}</version>  
  103.             </dependency>  
  104.             <!-- ant 会员业务jar -->  
  105.             <dependency>  
  106.                 <groupId>com.sml.sz</groupId>  
  107.                 <artifactId>ant-core-member</artifactId>  
  108.                 <version>${project.version}</version>  
  109.             </dependency>  
  110.               
  111.             <!-- ant RestFul服务系統 -->  
  112.             <dependency>  
  113.                 <groupId>com.sml.sz</groupId>  
  114.                 <artifactId>ant-web-service</artifactId>  
  115.                 <version>${project.version}</version>  
  116.             </dependency>  
  117.             <!-- ant admin后台管理系統 -->  
  118.             <dependency>  
  119.                 <groupId>com.sml.sz</groupId>  
  120.                 <artifactId>ant-web-admin</artifactId>  
  121.                 <version>${project.version}</version>  
  122.             </dependency>  
  123.   
  124.             <!-- dubbo begin -->  
  125.             <dependency>  
  126.                 <groupId>com.sml.sz</groupId>  
  127.                 <artifactId>ant-member-facade</artifactId>  
  128.                 <version>${project.version}</version>  
  129.             </dependency>  
  130.             <dependency>  
  131.                 <groupId>com.sml.sz</groupId>  
  132.                 <artifactId>ant-member-service</artifactId>  
  133.                 <version>${project.version}</version>  
  134.             </dependency>  
  135.             <!-- dubbo end -->  
  136.         </dependencies>  
  137.     </dependencyManagement>  
  138.   
  139.     <build>  
  140.         <pluginManagement>  
  141.             <plugins>  
  142.                 <!-- maven -->  
  143.                 <plugin>  
  144.                     <groupId>org.apache.maven.plugins</groupId>  
  145.                     <artifactId>maven-antrun-plugin</artifactId>  
  146.                     <version>1.7</version>  
  147.                 </plugin>  
  148.                 <plugin>  
  149.                     <groupId>org.apache.maven.plugins</groupId>  
  150.                     <artifactId>maven-compiler-plugin</artifactId>  
  151.                     <version>2.3.2</version>  
  152.                     <configuration>  
  153.                         <source>1.5</source>  
  154.                         <target>1.5</target>  
  155.                         <!-- 去除临时文件 -->  
  156.                         <excludes>  
  157.                             <exclude>**/*.keep</exclude>  
  158.                             <exclude>**/*.keep.*</exclude>  
  159.                             <exclude>*.bak</exclude>  
  160.                             <exclude>*.contrib</exclude>  
  161.                         </excludes>  
  162.                         <showDeprecation>true</showDeprecation>  
  163.                         <compilerArgument>-Xlint:unchecked,deprecation,fallthrough,finally</compilerArgument>  
  164.                         <fork>true</fork>  
  165.                         <encoding>${project.build.sourceEncoding}</encoding>  
  166.                     </configuration>  
  167.                 </plugin>  
  168.                 <plugin>  
  169.                     <groupId>org.apache.maven.plugins</groupId>  
  170.                     <artifactId>maven-jar-plugin</artifactId>  
  171.                     <version>2.3.1</version>  
  172.                     <executions>  
  173.                         <execution>  
  174.                             <goals>  
  175.                                 <goal>test-jar</goal>  
  176.                             </goals>  
  177.                         </execution>  
  178.                     </executions>  
  179.                     <configuration>  
  180.                         <archive>  
  181.                             <manifest>  
  182.                                 <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>  
  183.                                 <addDefaultImplementationEntries>true</addDefaultImplementationEntries>  
  184.                             </manifest>  
  185.                         </archive>  
  186.                     </configuration>  
  187.                 </plugin>  
  188.                 <plugin>  
  189.                     <groupId>org.apache.maven.plugins</groupId>  
  190.                     <artifactId>maven-release-plugin</artifactId>  
  191.                     <version>2.1</version>  
  192.                 </plugin>  
  193.                 <plugin>  
  194.                     <groupId>org.apache.maven.plugins</groupId>  
  195.                     <artifactId>maven-resources-plugin</artifactId>  
  196.                     <version>2.4.3</version>  
  197.                     <configuration>  
  198.                         <!-- 去除临时文件 -->  
  199.                         <excludes>  
  200.                             <exclude>**/*.keep</exclude>  
  201.                             <exclude>**/*.keep.*</exclude>  
  202.                             <exclude>*.bak</exclude>  
  203.                             <exclude>*.contrib</exclude>  
  204.                         </excludes>  
  205.                     </configuration>  
  206.                 </plugin>  
  207.                 <plugin>  
  208.                     <groupId>org.apache.maven.plugins</groupId>  
  209.                     <artifactId>maven-site-plugin</artifactId>  
  210.                     <version>2.1.1</version>  
  211.                     <configuration>  
  212.                         <inputEncoding>${project.build.sourceEncoding}</inputEncoding>  
  213.                         <outputEncoding>${project.build.sourceEncoding}</outputEncoding>  
  214.                     </configuration>  
  215.                 </plugin>  
  216.                 <plugin>  
  217.                     <groupId>org.apache.maven.plugins</groupId>  
  218.                     <artifactId>maven-source-plugin</artifactId>  
  219.                     <version>2.1.2</version>  
  220.                     <executions>  
  221.                         <execution>  
  222.                             <id>attach-sources</id>  
  223.                             <goals>  
  224.                                 <goal>jar</goal>  
  225.                                 <goal>test-jar</goal>  
  226.                             </goals>  
  227.                         </execution>  
  228.                     </executions>  
  229.                     <configuration>  
  230.                         <excludeResources>false</excludeResources>  
  231.                         <attach>true</attach>  
  232.                     </configuration>  
  233.                 </plugin>  
  234.                 <plugin>  
  235.                     <groupId>org.apache.maven.plugins</groupId>  
  236.                     <artifactId>maven-war-plugin</artifactId>  
  237.                     <version>2.4</version>  
  238.                 </plugin>  
  239.                 <plugin>  
  240.                     <groupId>org.apache.maven.plugins</groupId>  
  241.                     <artifactId>maven-ear-plugin</artifactId>  
  242.                     <version>2.9</version>  
  243.                     <configuration>  
  244.                         <version>5</version>  
  245.                     </configuration>  
  246.                 </plugin>  
  247.                 <plugin>  
  248.                     <groupId>org.apache.maven.plugins</groupId>  
  249.                     <artifactId>maven-surefire-plugin</artifactId>  
  250.                     <version>2.6</version>  
  251.                     <configuration>  
  252.                         <testFailureIgnore>true</testFailureIgnore>  
  253.                     </configuration>  
  254.                 </plugin>  
  255.                 <plugin>  
  256.                     <groupId>org.apache.maven.plugins</groupId>  
  257.                     <artifactId>maven-surefire-report-plugin</artifactId>  
  258.                     <version>2.6</version>  
  259.                     <configuration>  
  260.                         <parallel>both</parallel>  
  261.                     </configuration>  
  262.                 </plugin>  
  263.                 <plugin>  
  264.                     <groupId>com.google.code.maven-replacer-plugin</groupId>  
  265.                     <artifactId>replacer</artifactId>  
  266.                     <version>1.5.1</version>  
  267.                     <executions>  
  268.                         <execution>  
  269.                             <phase>prepare-package</phase>  
  270.                             <goals>  
  271.                                 <goal>replace</goal>  
  272.                             </goals>  
  273.                         </execution>  
  274.                     </executions>  
  275.                 </plugin>  
  276.   
  277.                 <!-- 读取系统配置的properties文件,避免写入profile中,各自模块使用的时候注意修改路径 -->  
  278.                 <plugin>  
  279.                     <groupId>org.kuali.maven.plugins</groupId>  
  280.                     <artifactId>properties-maven-plugin</artifactId>  
  281.                     <version>2.0.1</version>  
  282.                     <configuration>  
  283.                         <locations>  
  284.                             <location>${basedir}/../project_${profile}.properties</location>  
  285.                         </locations>  
  286.                     </configuration>  
  287.                     <executions>  
  288.                         <execution>  
  289.                             <phase>prepare-package</phase>  
  290.                             <goals>  
  291.                                 <goal>read-project-properties</goal>  
  292.                             </goals>  
  293.                         </execution>  
  294.                     </executions>  
  295.                 </plugin>  
  296.             </plugins>  
  297.         </pluginManagement>  
  298.     </build>  
  299.     <profiles>  
  300.         <profile>  
  301.             <id>dev</id>  
  302.             <activation>  
  303.                 <activeByDefault>true</activeByDefault>  
  304.             </activation>  
  305.             <properties>  
  306.                 <project>  
  307.                     dev  
  308.                 </project>  
  309.             </properties>  
  310.         </profile>  
  311.         <profile>  
  312.             <id>sit</id>  
  313.             <activation>  
  314.                 <property>  
  315.                     <name>environment.type</name>  
  316.                     <value>sit</value>  
  317.                 </property>  
  318.             </activation>  
  319.             <properties>  
  320.                 <project>  
  321.                     sit  
  322.                 </project>  
  323.             </properties>  
  324.         </profile>  
  325.         <profile>  
  326.             <id>uat</id>  
  327.             <activation>  
  328.                 <property>  
  329.                     <name>environment.type</name>  
  330.                     <value>uat</value>  
  331.                 </property>  
  332.             </activation>  
  333.             <properties>  
  334.                 <project>  
  335.                     uat  
  336.                 </project>  
  337.             </properties>  
  338.         </profile>  
  339.         <profile>  
  340.             <id>performance</id>  
  341.             <activation>  
  342.                 <property>  
  343.                     <name>environment.type</name>  
  344.                     <value>performance</value>  
  345.                 </property>  
  346.             </activation>  
  347.             <properties>  
  348.                 <project>  
  349.                     performance  
  350.                 </project>  
  351.             </properties>  
  352.         </profile>  
  353.         <profile>  
  354.             <id>production</id>  
  355.             <activation>  
  356.                 <property>  
  357.                     <name>environment.type</name>  
  358.                     <value>production</value>  
  359.                 </property>  
  360.             </activation>  
  361.             <properties>  
  362.                 <project>  
  363.                     production  
  364.                 </project>  
  365.             </properties>  
  366.         </profile>  
  367.     </profiles>  
  368.   
  369.     <modules>  
  370.         <!-- ant 工具jar -->  
  371.         <module>ant-utils</module>  
  372.   
  373.         <!-- ant 公共配置jar -->  
  374.         <module>ant-config</module>  
  375.   
  376.         <!-- ant 核心框架jar -->  
  377.         <module>ant-framework</module>  
  378.   
  379.         <!-- ant 代码自动生成业务jar -->  
  380.         <module>ant-core-gen</module>  
  381.   
  382.         <!-- ant 会员业务jar -->  
  383.         <module>ant-core-member</module>  
  384.   
  385.         <!-- ant admin后台管理系統 -->  
  386.         <module>ant-web-admin</module>  
  387.   
  388.         <!-- ant Restful服务管理系統 -->  
  389.         <module>ant-web-service</module>  
  390.   
  391.         <!-- ant member Dubbo服务接口 -->  
  392.         <module>ant-member-facade</module>  
  393.   
  394.         <!-- ant member Dubbo服务提供者 -->  
  395.         <module>ant-member-service</module>  
  396.     </modules>  
  397.     <description>ant平台的super工程,定义了整合ant项目群的基本信息,以及依赖项和插件信息、maven的自定义信息</description>  
  398. </project></span>  

2. 创建打包脚本:测试、生成等

[html]  view plain  copy
  1. <span style="font-size: 16px;">set MAVEN_OPTS= -Xms128 -Xmx256m  
  2. mvn clean package --define maven.test.skip=true --define environment.type=sit</span>  
[html]  view plain  copy
  1. <span style="font-size: 16px;">set MAVEN_OPTS= -Xms128 -Xmx256m  
  2. mvn clean package --define maven.test.skip=true --define environment.type=pro</span>  
[html]  view plain  copy
  1. <span style="font-size: 16px;">set MAVEN_OPTS= -Xms128 -Xmx256m  
  2. mvn clean package --define maven.test.skip=true --define environment.type=pro</span>  

3. 创建打包的properties文件:

解释: 里面可以配置打包的信息,比如:ip、域名、包名等

4. 代码结构如下:


-----------------------------------------------------------------------

完整的项目源码来源  欢迎大家一起学习研究相关技术,源码获取请加求求:2670716182



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值