(十) 構建dubbo分散式平臺-maven構建ant-utils工具專案

smileday發表於2017-12-13

上一篇我們介紹《構建dubbo分散式平臺-maven構建ant-framework核心程式碼Base封裝》,今天重點講解的是ant-utils工具包的構建過程。

導語:ant-utils是核心工具包,提供整個架構通用工具類庫

1. 建立ant-utils工具包子專案,繼承ant-parent根專案,其中pom.xml配置如下:

<span style="font-size: 14px;"><?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.sml.sz</groupId>
<artifactId>ant-project</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>ant-utils</artifactId>
<name>ant-utils</name>
<url>http://maven.apache.org</url>
<description>ant核心工具包,提供整個架構通用工具類庫</description>

<dependencies>
<!-- 通用工具包 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>${commons-io.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>${commons-fileupload.version}</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>${commons-beanutils.version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- jackson json 包-->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-jaxb-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>

<!-- xstream包,將Java物件和xml文件相互轉換-->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>${xstream.version}</version>
</dependency>

<!-- pojo copy javaBean的對映工具包,可以進行簡單的屬性對映、複雜的型別對映、雙向對映、遞迴對映-->
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>${dozer.version}</version>
</dependency>

<!-- freemarker 模板引擎包 -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>${freemarker.version}</version>
</dependency>

<!-- java郵件傳送 -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>${email.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>

<!-- POI相關的包 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${poi.version}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>${poi.version}</version>
</dependency>

<!-- 圖片資料元提取 -->
<dependency>
<groupId>com.drewnoakes</groupId>
<artifactId>metadata-extractor</artifactId>
<version>2.6.2</version>
</dependency>

<!-- 條形碼、二維碼生成 -->
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>2.2</version>
</dependency>

<!-- 快取相關包 -->
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>${ehcache.version}</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-web</artifactId>
<version>${ehcache-web.version}</version>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.5.1</version>
</dependency>

<!-- spring相關包 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- httpclient 依賴包,使用的時候才依賴 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
</dependencies>
<profiles>
<profile>
<id>sit</id>
<activation>
<property>
<name>environment.type</name>
<value>sit</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<configuration>
<includes>
<include>target/classes/logback.properties</include>
</includes>
<replacements>
<replacement>
<token>=dev</token>
<value>=sit</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>uat</id>
<activation>
<property>
<name>environment.type</name>
<value>uat</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<configuration>
<includes>
<include>target/classes/logback.properties</include>
</includes>
<replacements>
<replacement>
<token>=dev</token>
<value>=uat</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>performance</id>
<activation>
<property>
<name>environment.type</name>
<value>performance</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<configuration>
<includes>
<include>target/classes/logback.properties</include>
</includes>
<replacements>
<replacement>
<token>=dev</token>
<value>=perf</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>production</id>
<activation>
<property>
<name>environment.type</name>
<value>production</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<configuration>
<includes>
<include>target/classes/logback.properties</include>
</includes>
<replacements>
<replacement>
<token>=dev</token>
<value>=prd</value>
</replacement>
</replacements>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project></span>

2. 此專案中只包含了通用的工具類庫,包括:配置檔案、檔案處理、手機簡訊、email郵箱處理、

redis快取處理、collection集合處理、cookie處理、時間工具、freemarker模板工具、httpclient工具、

多執行緒等。更多詳細原始碼參考來源

歡迎大家跟我一起學習《構建dubbo分散式平臺》,希望大家持續關注後面的文章!

願意瞭解框架技術或者原始碼的朋友直接求求交流分享技術:2042849237
分散式的一些解決方案,有願意瞭解的朋友可以找我們團隊探討


相關文章