Maven工程的多模塊

一個大項目需要一個團隊來完成,然后一個大型項目就拆分成幾塊來同時開發,節省時間,提高效率.

大致分為以下幾個模塊(僅是自身經歷):
依賴管理工程模塊:一般現在開發都是以maven來管理jar包,方便.所以整個工程的依賴統一放在一個單獨工程中,一般叫做父工程xxx-parent.
注意事項:父工程打包方式設置成pom
創建父工程時,不要勾選maven模板,他就是一個管理依賴的,不處理業務.如下圖
在這里插入圖片描述
pom文件格式如下:

<?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.qiushiju</groupId><artifactId>xxx-parent</artifactId><version>1.0-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</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-context-support</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-web</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.8</source><target>1.8</target><encoding>UTF-8</encoding></configuration></plugin></plugins><pluginManagement><plugins><!--&lt;!&ndash; 配置Tomcat插件 &ndash;&gt;--><plugin><groupId>org.apache.tomcat.maven</groupId><artifactId>tomcat-maven-plugin</artifactId><version>2.2</version></plugin></plugins></pluginManagement></build></project>

pom文件中的< properties>< /properties>標簽內是下面< dependencies>< /dependencies>標簽中的版本號,把它們提取出來,便于方便管理.
把這個工程編譯安裝進本地倉庫,這樣后面其他的工程才能使用IDEA中是這樣操作
在這里插入圖片描述
其他模塊怎么使用父工程的依賴,下面幾個模塊介紹
公共工程模塊(common):這個工程內放置的是整個項目要用用的公共類,例如日期格式類(DataUtil.java)、分頁結果類(PafeReult.java)、封裝JSON結果類(JsonResult.java)等等….
創建公共工程(xxx-common),使用maven創建一個java工程,因為它只提供幾個類,不做web項目.如圖
在這里插入圖片描述
打包方式為jar包.因為它其中的類需要被別的工程使用.可以在pom.xml文件中寫,指定打包方式

<packaging>jar</packaging>

繼承父工程(xxx-parent).在pom.xml文件中寫入如下代碼

<parent><groupId>com.qiushiju</groupId><artifactId>xxx-parent</artifactId><version>1.0-SNAPSHOT</version></parent>

寫入本工程實際需要的依賴(從父工程中copy,不需版本信息)比如

<dependencies>
.
.
.<!-- 日志處理 --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId></dependency>...</dependencies>

把xxx-common工程也編譯打包安裝進本地倉庫,方便別人調用,打包方式參考上面

開發工程模塊(比如后臺管理系統或者前臺管理系統xxx-manager):這個模塊一般都是MVC架構,所以需要三個子模塊來分開開發以提升效率.三個子模塊分別是
xxx-manager-pojo、xxx-manager-controller、xxx-manager-service、xxx-manager-dao。如圖項目結構
在這里插入圖片描述
先說xxx-manager的pom.xml,①它需要繼承xxx-parent使用它的依賴,②還有需要加入xxx-common的依賴,要使用其中的工具類
部分代碼:

 <packaging>pom</packaging><parent><groupId>com.qiushiju</groupId><artifactId>xxx-parent</artifactId><version>1.0-SNAPSHOT</version></parent><!-- 依賴管理 -->
<dependencies><!-- 加入common依賴 --><dependency><groupId>com.qiushiju</groupId><artifactId>xxx-common</artifactId><version>1.0-SNAPSHOT</version></dependency>...</dependencies><modules><module>xxx-manager-pojo</module><module>xxx-manager-mapper</module><module>xxx-manager-service</module><module>xxx-manager-controller</module></modules>

①從上面代碼看到xxx-manager的打包方式要為pom.因為它的幾個子模塊要使用它的依賴.
②沒有別的依賴,因為依賴在四個子模塊的各自pom.xml文件中寫著,每個模塊寫各自所需的依賴
③< module>標簽,創建一個子模塊就會自動出來這一標簽~
現在來說在xxx-manager的基礎上創建子項目,方法如下:xxx-manager項目上右鍵-new-module
在這里插入圖片描述
同樣的步驟創建其他子模塊.每個子類創建成功后,在自己的pom.xml文件中都會自動有< parent>標簽來繼承父類,

<!-- 繼承父類 --><parent><artifactId>xxx-manager</artifactId><groupId>com.qiushiju</groupId><version>1.0-SNAPSHOT</version></parent><dependencies><!-- controller需要service的依賴, --><!-- 在xxx-manager-service的pom文件中,也需要dao層的依賴 --><dependency><groupId>com.qiushiju</groupId><artifactId>xxx-manager-service</artifactId><version>1.0-SNAPSHOT</version></dependency><!-- JSP相關 --><dependency><groupId>jstl</groupId><artifactId>jstl</artifactId></dependency><dependency><groupId>javax.servlet</groupId><artifactId>servlet-api</artifactId><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jsp-api</artifactId><scope>provided</scope></dependency>..</dependencies>

特殊的,①pojo,service,dao模塊需要打包方式為jar,因為controller需要使用它們的類.而controller模塊是需要創建為webapp,
②dao層使用mybatis,因此會有Mapper.xml文件.因此打包時會出錯,需要在xxx-manager-dao的pom文件中加入配置代碼,代碼如下

 <!-- 如果不添加此節點mybatis的mapper.xml文件都會被漏掉。 --><build><resources><resource><directory>src/main/java</directory><includes><include>**/*.properties</include><include>**/*.xml</include></includes><filtering>false</filtering></resource></resources></build>

ssm的配置文件寫在xxx-manager-controller的src-main-resource目錄下與java同級.靜態文件放在wabapp下
在這里插入圖片描述
如果新建的工程沒有這三個文件夾,就自己創建.然后mark這個文件夾為相應的資源文件
在這里插入圖片描述
注意:不管哪一個模塊修改,都需要重新編譯,打包,安裝進倉庫,才能時時更新,別的工程才能調用.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/249380.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/249380.shtml
英文地址,請注明出處:http://en.pswp.cn/news/249380.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

《淺談架構之路:前后端分離模式》

前言&#xff1a;分離模式 對前后端分離研究了一段時間&#xff0c;恰逢公司有一個大項目決定嘗試使用前后端分離模式進行&#xff0c;便參與其中。該項目從2016年初立項至今&#xff0c;平平穩穩得度過&#xff0c;但也涌現出越來越多的問題&#xff0c;絕對不是說前后端分離模…

查詢語句

1.基本查詢語句 1.1 語法&#xff1a; SELECT 屬性列表 FROM 表名或視圖列表 WHERE 條件表達式1 GROUP BY 屬性名1 | HAVING 條件表達式2 ORDER BY 屬性名2 ASC DESC 2.單表查詢 1.應用&#xff1a;查詢表中所有的記錄 2.查詢指定字段&#xff1a;查詢表中所有name字段的記錄 …

Nodejs+Koa2+云服務ECS 開發微信公眾號(一)之環境配置

硬件準備工作 1. 本人采用阿里云的云服務器&#xff0c;購買了入門級云服務ECS&#xff08;293元每年&#xff09;&#xff1b; 2.針對服務器進行認證&#xff0c;設置個人服務器密碼&#xff1b; 3.購買數據盤&#xff0c;并將其掛載于云服務器之上&#xff08;建議掛載在/…

中文詞頻統計與詞云生成

本次作業來源于&#xff1a;https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2822 中文詞頻統計 1. 下載一長篇中文小說。 下載長篇小說《西游記》 本次作業小說保存在txt文檔&#xff1a;xyj.txt 2. 從文件讀取待分析文本。 xyj open(rF:/xyj.txt,r,encodingutf-8)…

java SWT Browser實現瀏覽器功能并運行JavaScript代碼

一、創建簡單的瀏覽器 import org.eclipse.swt.*; import org.eclipse.swt.browser.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*;public class Myswt3 {public static void main(String [] args) {Display display new Display();final Shell she…

[JZOJ5866]【NOIP2018模擬9.13】指引

Description Input Output Sample Input 6 3 2 0 3 1 1 3 4 2 0 4 5 5 Sample Output 2 Data Constraint Hint 貪心&#xff0c;把旅行者和出口的x坐標降序排序。 然后從前往后掃&#xff0c;如果是出口&#xff0c;就把y坐標插進set里&#xff0c;如果是旅行者&#xff0c;就查…

scrapy框架之遞歸解析和post請求

今日概要 遞歸爬取解析多頁頁面數據scrapy核心組件工作流程scrapy的post請求發送今日詳情 1.遞歸爬取解析多頁頁面數據 - 需求&#xff1a;將糗事百科所有頁碼的作者和段子內容數據進行爬取切持久化存儲 - 需求分析&#xff1a;每一個頁面對應一個url&#xff0c;則scrapy工程需…

SmartGit 過期解決方案之 非商業版本安裝使用

作為前端開發的小伙伴一定有這樣的困惑&#xff0c;自己在日常的團隊協作配合時&#xff0c;提交代碼和解決沖突是我們最頭疼的問題&#xff0c;但是又不喜歡使用Eclipse或者IDEA這種超級占內存的編輯器&#xff0c;使用Git命令又是那么捉襟見肘&#xff0c;所以有一個好用的輕…

HDU6438 Buy and Resell 解題報告(一個有趣的貪心問題的嚴格證明)

寫在前面 此題是一個很容易想到的貪心題目&#xff0c;但是正確性的證明是非常復雜的。然而&#xff0c;目前網上所有題解并未給出本題貪心算法的任何正確性證明&#xff0c;全部僅停留在描述出一個貪心算法。本著對算法與計算機科學的熱愛&#xff08;逃&#xff09;&#xff…

Webpack不生成index.html

沒有導出你的最后2個插件&#xff0c;并且沒有指定html文件名dist&#xff0c;因為HtmlWebpackPlugin應該生成相對于path&#xff0c;下面是固定配置&#xff1a; var path require(path)var webpack require(webpack)var HtmlWebpackPlugin require(html-webpack-plugin);m…

CSS3筆記之定位篇(一)relative

知識點1&#xff1a;relative和absolute relative: 相對自身&#xff0c;并會限制內部absolute元素層疊 absolute: 相對容器&#xff0c;并受到父類容器relative的影響&#xff0c;比如&#xff1a;overflow:hidden/scroll fixed: 不受relative限制&#xff0c;只受z-index的…

洛谷P3066 [USACO12DEC]逃跑的BarnRunning Away From…

題面鏈接 一句話題意&#xff1a;給出以1號點為根的一棵有根樹&#xff0c;問每個點的子樹中與它距離小于等于l的點有多少個。 我&#xff1a;似乎并不好做啊。。。看了題解后大霧。。。 sol&#xff1a;考慮樹上差分&#xff0c;對于一個點&#xff0c;在他那個位置&#xff0…

vue使用webPack打包發布后頁面顯示空白

今天筆者將打包后&#xff0c;進行訪問&#xff0c;訪問到index.html&#xff0c;但是出現的是空白頁。 打包命令&#xff1a;npm run build&#xff0c;打包后的文件如下&#xff1a; 這是因為index.html中引入的css ,js 的路徑不對:如下圖 這個是因為webpack打包的時候引入…

第一次實驗報告

c程序實驗報告 姓名&#xff1a;黃志乾 實驗地點&#xff1a;教學樓514教室 實驗時間&#xff1a;3月19日實驗項目: 1、字符與ASCII碼 2、運算符與表達式的應用 3、順序結構應用程序 4、數學函數的算法描述 5、雞兔同籠的算法描述 6、確定坐標的算法描述…

Mac下Idea安裝Git報錯Xcrun問題的解決

使用過IDEA的小伙伴都知道&#xff0c;它和我們之前用過的Eclipse一樣強大&#xff0c;或者比他更強大。當它配合的Mac使用時&#xff0c;就會變得更得心應手&#xff0c;少去很多環境配置的環節。其中最典型的就是Git 由于Mac自帶就安裝了git, 大家可以通過終端輸入命令“git…

關于Django路由層簡單筆記

Django—路由層 URL配置(URLconf)就像Django 所支撐網站的目錄。它的本質是URL與要為該URL調用的視圖函數之間的映射表&#xff1b;你就是以這種方式告訴Django&#xff0c;對于客戶端發來的某個URL調用哪一段邏輯代碼對應執行。 1&#xff0c;簡單的路由配置 from django.urls…

hdu 5183

hdu 5183(Hash處理區間問題) 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid5183 題意:給出一個n個元素的數組,現在要求判斷 a1-a2a3-a4...../-an 中是否存在某個某個區間使得 ai-ai1ai2...(-1)j-iaj k?? 這個題要利用Hash就可以實現幾乎在 O(n) 的時間內實現查找判斷…

vue-cli,webpack安裝

第一步應該下載node.js這是安裝vue-cli的基礎工具。官網下載快捷安全可&#xff1a;https://nodejs.org/en/ 第二步打開命令面板找到你要安裝的位置 第三步就是安裝全局vue-cli 命令操作 npm intatll -g vue-cli 安裝完畢之后 可以檢查安裝版本即 vue -V 如下圖 這還不算完&…

CSS3筆記之定位篇(二)z-index

知識點1&#xff1a;z-index基礎 z-index&#xff1a;auto; 默認值 z-index: <integer> 整數 z-index: inherit 繼承 不考慮css3 還有定位元素的z-index才有作用 知識點2&#xff1a;z-index與定位元素 無嵌套&#xff1a;后來居上&#xff0c;哪個大哪個上 //在沒有…

JSP頁面傳值出現中文亂碼的問題

在接收值的jsp頁面代碼的body里添加&#xff1a; <%request.setCharacterEncoding("utf-8"); %> //這里是設置utf-8為jsp頁面的中文編碼方式 jsp頁面之間傳值&#xff1a; 發送信息的jsp腳本&#xff1a; session.setAttribute("user",rs.getString…