從netty項目組織入門maven的多modules模組配置

來源:互聯網
上載者:User

標籤:maven   netty   modules   專案管理   

Netty是一套提供非同步、事件驅動的網路應用程式架構,同時也是工具包。我們可以將它作為項目的核心架構,同時也可以用他提供的部分功能來對項目進行支援,因此項目功能的模組化就顯得很重要,這也是我們平時做項目所追求的可重用性。
netty一個項目整體的組織如下:
。
這裡不說項目的各個子模組的功能,只是看如何?項目模組的分離和組織。

在我們平時的開發中可能會有一個這樣子的結構:

如果是一個小項目這樣做也不錯,至少做到了比較低層次的“高內聚,低耦合”。但是如果有10個這樣的小項目,每個都會用到其中的util包,那麼就會比較難過了,單是每個項目去同步util的狀態就會耗很多精力。
如果用maven的模組化來進行管理會優美許多:

來看一下項目的構成:
首先tiegr-parent項目是我們真正的主專案,他包含了3個子模組:tiger-all,tiger-modules1和tiger-util 3個子模組。每個模組可以作為單獨的項目進行開發和管理。並且這樣做最直接的表現就是可重用性的提高以及模組間耦合度的降低。項目間的依賴完全有設定檔進行管理。
下面是類比的項目間的依賴關係及配置:

<!-- tiger-parent/pom.xml --><?xml version="1.0" encoding="UTF-8"?><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.tiger</groupId>    <artifactId>app-parent</artifactId>    <packaging>pom</packaging>    <version>1.0</version>    <modules>        <module>tiger-modules1</module>      <module>tiger-util</module>      <module>tiger-all</module>  </modules> </project>
<!-- tiger-modules1/pom.xml --><?xml version="1.0" encoding="UTF-8"?><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.tiger</groupId>    <artifactId>app-parent</artifactId>    <version>1.0</version>  </parent>  <artifactId>tiger-modules1</artifactId>  <packaging>jar</packaging>  <name>tiger-modules1</name>  <dependencies>    <dependency>        <groupId>${project.groupId}</groupId>        <artifactId>tiger-util</artifactId>        <version>${project.version}</version>    </dependency>  </dependencies></project>
<!-- tiger-util/pom.xml --><?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.tiger</groupId>    <artifactId>app-parent</artifactId>    <version>1.0</version>  </parent>  <artifactId>tiger-util</artifactId>  <packaging>jar</packaging>  <name>tiger-util</name>  <url>http://maven.apache.org</url>  <dependencies>    <!-- JUnit testing framework -->    <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>4.10</version>        <scope>test</scope>    </dependency>  </dependencies></project>

從這裡看出我們的項目間通過依賴關係進行管理,將每個模組或者說功能作為單獨的項目進行引入。不僅關係很清晰,而且還可以為每個模組做到最大化的“瘦身”。
代碼都這樣管理突然覺得整個人心情都好了很多,有沒有~^_^

從netty項目組織入門maven的多modules模組配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.