鱼C论坛

 找回密码
 立即注册
查看: 2714|回复: 1

[学习笔记] 构建dubbo分布式平台-maven构建根项目

[复制链接]
发表于 2018-8-29 14:30:42 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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文件和打包的文件即可,代码如下:
  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.     <groupId>com.sml.sz</groupId>
  5.     <artifactId>ant-project</artifactId>
  6.     <version>1.0.0</version>
  7.     <packaging>pom</packaging>

  8.     <name>ant-project</name>
  9.     <url>http://maven.apache.org</url>
  10.     <inceptionYear>2015-2016</inceptionYear>

  11.     <properties>
  12.         <!-- 框架通用包版本设置 -->
  13.         <spring.version>4.2.2.RELEASE</spring.version>
  14.         <validator.version>5.1.1.Final</validator.version>
  15.         <mybatis.version>3.2.8</mybatis.version>
  16.         <mybatis-spring.version>1.2.2</mybatis-spring.version>
  17.         <shiro.version>1.2.3</shiro.version>
  18.         <druid.version>1.0.11</druid.version>
  19.         <ehcache.version>2.6.9</ehcache.version>
  20.         <ehcache-web.version>2.0.4</ehcache-web.version>
  21.         <sitemesh.version>2.4.2</sitemesh.version>
  22.         <activiti.version>5.15.1</activiti.version>
  23.         <wink.version>1.4</wink.version>
  24.         <sso.client.version>3.2.1</sso.client.version>

  25.         <!-- 通用工具包版本设置 -->
  26.         <slf4j.version>1.7.7</slf4j.version>
  27.         <commons-lang3.version>3.3.2</commons-lang3.version>
  28.         <commons-io.version>2.4</commons-io.version>
  29.         <commons-codec.version>1.9</commons-codec.version>
  30.         <commons-fileupload.version>1.3.1</commons-fileupload.version>
  31.         <commons-beanutils.version>1.9.1</commons-beanutils.version>
  32.         <jackson.version>2.2.3</jackson.version>
  33.         <fastjson.version>1.1.40</fastjson.version>
  34.         <xstream.version>1.4.7</xstream.version>
  35.         <guava.version>17.0</guava.version>
  36.         <dozer.version>5.5.1</dozer.version>
  37.         <email.version>1.4.7</email.version>
  38.         <poi.version>3.9</poi.version>
  39.         <freemarker.version>2.3.20</freemarker.version>

  40.         <!-- 基础环境设置 -->
  41.         <jdk.version>1.6</jdk.version>
  42.         <tomcat.version>2.2</tomcat.version>
  43.         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  44.         <downloadSources>true</downloadSources>

  45.         <!-- jdbc驱动版本设置 -->
  46.         <mysql.driver.version>5.1.30</mysql.driver.version>
  47.     </properties>

  48.     <dependencies>
  49.         <!-- 单元测试 -->
  50.         <dependency>
  51.             <groupId>junit</groupId>
  52.             <artifactId>junit</artifactId>
  53.             <version>4.11</version>
  54.             <scope>test</scope>
  55.         </dependency>
  56.         <!-- Tomcat 如果存在就不需要将servlet-api.jar、jsp-api.jar一起打包 -->
  57.         <dependency>
  58.             <groupId>javax.servlet</groupId>
  59.             <artifactId>servlet-api</artifactId>
  60.             <version>2.5</version>
  61.             <scope>provided</scope>
  62.         </dependency>
  63.         <dependency>
  64.             <groupId>javax.servlet.jsp</groupId>
  65.             <artifactId>jsp-api</artifactId>
  66.             <version>2.1</version>
  67.             <scope>provided</scope>
  68.         </dependency>
  69.     </dependencies>

  70.     <dependencyManagement>
  71.         <dependencies>
  72.             <!-- ant 工具jar -->
  73.             <dependency>
  74.                 <groupId>com.sml.sz</groupId>
  75.                 <artifactId>ant-utils</artifactId>
  76.                 <version>${project.version}</version>
  77.             </dependency>
  78.             <!-- ant 公共配置jar -->
  79.             <dependency>
  80.                 <groupId>com.sml.sz</groupId>
  81.                 <artifactId>ant-config</artifactId>
  82.                 <version>${project.version}</version>
  83.             </dependency>
  84.             <!-- ant 核心框架jar -->
  85.             <dependency>
  86.                 <groupId>com.sml.sz</groupId>
  87.                 <artifactId>ant-framework</artifactId>
  88.                 <version>${project.version}</version>
  89.             </dependency>
  90.             <!-- ant 代码自动生成业务jar -->
  91.             <dependency>
  92.                 <groupId>com.sml.sz</groupId>
  93.                 <artifactId>ant-core-gen</artifactId>
  94.                 <version>${project.version}</version>
  95.             </dependency>
  96.             <!-- ant 会员业务jar -->
  97.             <dependency>
  98.                 <groupId>com.sml.sz</groupId>
  99.                 <artifactId>ant-core-member</artifactId>
  100.                 <version>${project.version}</version>
  101.             </dependency>
  102.             
  103.             <!-- ant RestFul服务系統 -->
  104.             <dependency>
  105.                 <groupId>com.sml.sz</groupId>
  106.                 <artifactId>ant-web-service</artifactId>
  107.                 <version>${project.version}</version>
  108.             </dependency>
  109.             <!-- ant admin后台管理系統 -->
  110.             <dependency>
  111.                 <groupId>com.sml.sz</groupId>
  112.                 <artifactId>ant-web-admin</artifactId>
  113.                 <version>${project.version}</version>
  114.             </dependency>

  115.             <!-- dubbo begin -->
  116.             <dependency>
  117.                 <groupId>com.sml.sz</groupId>
  118.                 <artifactId>ant-member-facade</artifactId>
  119.                 <version>${project.version}</version>
  120.             </dependency>
  121.             <dependency>
  122.                 <groupId>com.sml.sz</groupId>
  123.                 <artifactId>ant-member-service</artifactId>
  124.                 <version>${project.version}</version>
  125.             </dependency>
  126.             <!-- dubbo end -->
  127.         </dependencies>
  128.     </dependencyManagement>

  129.     <build>
  130.         <pluginManagement>
  131.             <plugins>
  132.                 <!-- maven -->
  133.                 <plugin>
  134.                     <groupId>org.apache.maven.plugins</groupId>
  135.                     <artifactId>maven-antrun-plugin</artifactId>
  136.                     <version>1.7</version>
  137.                 </plugin>
  138.                 <plugin>
  139.                     <groupId>org.apache.maven.plugins</groupId>
  140.                     <artifactId>maven-compiler-plugin</artifactId>
  141.                     <version>2.3.2</version>
  142.                     <configuration>
  143.                         <source>1.5</source>
  144.                         <target>1.5</target>
  145.                         <!-- 去除临时文件 -->
  146.                         <excludes>
  147.                             <exclude>**/*.keep</exclude>
  148.                             <exclude>**/*.keep.*</exclude>
  149.                             <exclude>*.bak</exclude>
  150.                             <exclude>*.contrib</exclude>
  151.                         </excludes>
  152.                         <showDeprecation>true</showDeprecation>
  153.                         <compilerArgument>-Xlint:unchecked,deprecation,fallthrough,finally</compilerArgument>
  154.                         <fork>true</fork>
  155.                         <encoding>${project.build.sourceEncoding}</encoding>
  156.                     </configuration>
  157.                 </plugin>
  158.                 <plugin>
  159.                     <groupId>org.apache.maven.plugins</groupId>
  160.                     <artifactId>maven-jar-plugin</artifactId>
  161.                     <version>2.3.1</version>
  162.                     <executions>
  163.                         <execution>
  164.                             <goals>
  165.                                 <goal>test-jar</goal>
  166.                             </goals>
  167.                         </execution>
  168.                     </executions>
  169.                     <configuration>
  170.                         <archive>
  171.                             <manifest>
  172.                                 <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
  173.                                 <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
  174.                             </manifest>
  175.                         </archive>
  176.                     </configuration>
  177.                 </plugin>
  178.                 <plugin>
  179.                     <groupId>org.apache.maven.plugins</groupId>
  180.                     <artifactId>maven-release-plugin</artifactId>
  181.                     <version>2.1</version>
  182.                 </plugin>
  183.                 <plugin>
  184.                     <groupId>org.apache.maven.plugins</groupId>
  185.                     <artifactId>maven-resources-plugin</artifactId>
  186.                     <version>2.4.3</version>
  187.                     <configuration>
  188.                         <!-- 去除临时文件 -->
  189.                         <excludes>
  190.                             <exclude>**/*.keep</exclude>
  191.                             <exclude>**/*.keep.*</exclude>
  192.                             <exclude>*.bak</exclude>
  193.                             <exclude>*.contrib</exclude>
  194.                         </excludes>
  195.                     </configuration>
  196.                 </plugin>
  197.                 <plugin>
  198.                     <groupId>org.apache.maven.plugins</groupId>
  199.                     <artifactId>maven-site-plugin</artifactId>
  200.                     <version>2.1.1</version>
  201.                     <configuration>
  202.                         <inputEncoding>${project.build.sourceEncoding}</inputEncoding>
  203.                         <outputEncoding>${project.build.sourceEncoding}</outputEncoding>
  204.                     </configuration>
  205.                 </plugin>
  206.                 <plugin>
  207.                     <groupId>org.apache.maven.plugins</groupId>
  208.                     <artifactId>maven-source-plugin</artifactId>
  209.                     <version>2.1.2</version>
  210.                     <executions>
  211.                         <execution>
  212.                             <id>attach-sources</id>
  213.                             <goals>
  214.                                 <goal>jar</goal>
  215.                                 <goal>test-jar</goal>
  216.                             </goals>
  217.                         </execution>
  218.                     </executions>
  219.                     <configuration>
  220.                         <excludeResources>false</excludeResources>
  221.                         <attach>true</attach>
  222.                     </configuration>
  223.                 </plugin>
  224.                 <plugin>
  225.                     <groupId>org.apache.maven.plugins</groupId>
  226.                     <artifactId>maven-war-plugin</artifactId>
  227.                     <version>2.4</version>
  228.                 </plugin>
  229.                 <plugin>
  230.                     <groupId>org.apache.maven.plugins</groupId>
  231.                     <artifactId>maven-ear-plugin</artifactId>
  232.                     <version>2.9</version>
  233.                     <configuration>
  234.                         <version>5</version>
  235.                     </configuration>
  236.                 </plugin>
  237.                 <plugin>
  238.                     <groupId>org.apache.maven.plugins</groupId>
  239.                     <artifactId>maven-surefire-plugin</artifactId>
  240.                     <version>2.6</version>
  241.                     <configuration>
  242.                         <testFailureIgnore>true</testFailureIgnore>
  243.                     </configuration>
  244.                 </plugin>
  245.                 <plugin>
  246.                     <groupId>org.apache.maven.plugins</groupId>
  247.                     <artifactId>maven-surefire-report-plugin</artifactId>
  248.                     <version>2.6</version>
  249.                     <configuration>
  250.                         <parallel>both</parallel>
  251.                     </configuration>
  252.                 </plugin>
  253.                 <plugin>
  254.                     <groupId>com.google.code.maven-replacer-plugin</groupId>
  255.                     <artifactId>replacer</artifactId>
  256.                     <version>1.5.1</version>
  257.                     <executions>
  258.                         <execution>
  259.                             <phase>prepare-package</phase>
  260.                             <goals>
  261.                                 <goal>replace</goal>
  262.                             </goals>
  263.                         </execution>
  264.                     </executions>
  265.                 </plugin>

  266.                 <!-- 读取系统配置的properties文件,避免写入profile中,各自模块使用的时候注意修改路径 -->
  267.                 <plugin>
  268.                     <groupId>org.kuali.maven.plugins</groupId>
  269.                     <artifactId>properties-maven-plugin</artifactId>
  270.                     <version>2.0.1</version>
  271.                     <configuration>
  272.                         <locations>
  273.                             <location>${basedir}/../project_${profile}.properties</location>
  274.                         </locations>
  275.                     </configuration>
  276.                     <executions>
  277.                         <execution>
  278.                             <phase>prepare-package</phase>
  279.                             <goals>
  280.                                 <goal>read-project-properties</goal>
  281.                             </goals>
  282.                         </execution>
  283.                     </executions>
  284.                 </plugin>
  285.             </plugins>
  286.         </pluginManagement>
  287.     </build>
  288.     <profiles>
  289.         <profile>
  290.             <id>dev</id>
  291.             <activation>
  292.                 <activeByDefault>true</activeByDefault>
  293.             </activation>
  294.             <properties>
  295.                 <project>
  296.                     dev
  297.                 </project>
  298.             </properties>
  299.         </profile>
  300.         <profile>
  301.             <id>sit</id>
  302.             <activation>
  303.                 <property>
  304.                     <name>environment.type</name>
  305.                     <value>sit</value>
  306.                 </property>
  307.             </activation>
  308.             <properties>
  309.                 <project>
  310.                     sit
  311.                 </project>
  312.             </properties>
  313.         </profile>
  314.         <profile>
  315.             <id>uat</id>
  316.             <activation>
  317.                 <property>
  318.                     <name>environment.type</name>
  319.                     <value>uat</value>
  320.                 </property>
  321.             </activation>
  322.             <properties>
  323.                 <project>
  324.                     uat
  325.                 </project>
  326.             </properties>
  327.         </profile>
  328.         <profile>
  329.             <id>performance</id>
  330.             <activation>
  331.                 <property>
  332.                     <name>environment.type</name>
  333.                     <value>performance</value>
  334.                 </property>
  335.             </activation>
  336.             <properties>
  337.                 <project>
  338.                     performance
  339.                 </project>
  340.             </properties>
  341.         </profile>
  342.         <profile>
  343.             <id>production</id>
  344.             <activation>
  345.                 <property>
  346.                     <name>environment.type</name>
  347.                     <value>production</value>
  348.                 </property>
  349.             </activation>
  350.             <properties>
  351.                 <project>
  352.                     production
  353.                 </project>
  354.             </properties>
  355.         </profile>
  356.     </profiles>

  357.     <modules>
  358.         <!-- ant 工具jar -->
  359.         <module>ant-utils</module>

  360.         <!-- ant 公共配置jar -->
  361.         <module>ant-config</module>

  362.         <!-- ant 核心框架jar -->
  363.         <module>ant-framework</module>

  364.         <!-- ant 代码自动生成业务jar -->
  365.         <module>ant-core-gen</module>

  366.         <!-- ant 会员业务jar -->
  367.         <module>ant-core-member</module>

  368.         <!-- ant admin后台管理系統 -->
  369.         <module>ant-web-admin</module>

  370.         <!-- ant Restful服务管理系統 -->
  371.         <module>ant-web-service</module>

  372.         <!-- ant member Dubbo服务接口 -->
  373.         <module>ant-member-facade</module>

  374.         <!-- ant member Dubbo服务提供者 -->
  375.         <module>ant-member-service</module>
  376.     </modules>
  377.     <description>ant平台的super工程,定义了整合ant项目群的基本信息,以及依赖项和插件信息、maven的自定义信息</description>
  378. </project></span>
复制代码

2. 创建打包代码:测试、生成等

build_SIT-no

  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>
复制代码

build_UAT-no-test.bat

  1. <span style="font-size: 16px;">set MAVEN_OPTS= -Xms128 -Xmx256m  
  2. mvn clean package --define maven.test.skip=true --define environment.type=uat</span>  
复制代码


build_PROD-no-test.bat

  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文件:

project_sit.properties

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

4. 代码结构如下:
构建跟.png
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-8-29 14:31:18 | 显示全部楼层
愿意了解框架技术或者源码的朋友直接求求交流分享技术 贰零四贰八四九贰叁柒
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-7 22:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表