Maven多模塊項(xiàng)目,適用于一些比較大的項(xiàng)目,通過(guò)合理的模塊拆分,實(shí)現(xiàn)代碼的復(fù)用,便于維護(hù)和管理。尤其是一些開(kāi)源框架,也是采用多模塊的方式,提供插件集成,用戶可以根據(jù)需要配置指定的模塊。
10年的白塔網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。全網(wǎng)整合營(yíng)銷(xiāo)推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整白塔建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)從事“白塔網(wǎng)站設(shè)計(jì)”,“白塔網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
項(xiàng)目結(jié)構(gòu)如下:
test-hd-parent (父級(jí)) ---pom.xml ---test-hd-api (第三方接口層) ----pom.xml ---test-hd-foundation (基礎(chǔ)工具層) ----pom.xml ---test-hd-resource (資源層) ----pom.xml ---test-hd-service (邏輯業(yè)務(wù)層) ----pom.xml ---test-hd-modules (web層) ----pom.xml ---test-hd-www (web模塊1) ----pom.xml ---test-hd-admin (web模塊2) ----pom.xml
創(chuàng)建一個(gè)父maven工程
新建一個(gè)maven項(xiàng)目,選擇存儲(chǔ)位置,并選擇創(chuàng)建一個(gè)簡(jiǎn)單的maven工程
輸入Group Id、Artifact Id、Packaging,packaging選擇pom包
生成父工程,pom.xml如下
刪除工程中的src 目錄
創(chuàng)建子模塊
右擊父工程名---》New---》Project,然后選擇新建一個(gè)maven module工程
設(shè)置子工程名以及父工程,再設(shè)置快速創(chuàng)建模式
得到子工程(test-hd-api,第三方接口層),設(shè)置編譯的jdk
同理設(shè)置,子模塊:test-hd-foundation(基礎(chǔ)工具層)、test-hd-resource(資源層) 、test-hd-service(邏輯業(yè)務(wù)層)
新建test-hd-modules (web層),選擇創(chuàng)建一個(gè)a simple project,輸入Group Id、Artifact Id、Packaging,packaging選擇pom包
創(chuàng)建web子模塊
web子模塊在建在test-hd-modules (web層)里面,右擊test-hd-modules 工程名---》New---》Project,然后選擇新建一個(gè)maven module工程,設(shè)置子工程名以及父工程,選擇新建web項(xiàng)目
配置maven web項(xiàng)目,參照:【Maven】Eclipse 使用Maven創(chuàng)建Java Web項(xiàng)目
同理可以配置其他的web子模塊 test-hd-admin(web模塊2)
配置個(gè)模塊的依賴(lài)
在parent項(xiàng)目pom.xml中建立依賴(lài)管理(dependencyManagement)
<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.hd</groupId> <artifactId>test-hd-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <modules> <module>test-hd-api</module> <module>test-hd-service</module> <module>test-hd-resource</module> <module>test-hd-foundation</module> <module>test-hd-modules</module> </modules> <!-- maven依賴(lài) --> <dependencyManagement> <dependencies> <!-- hd --> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-api</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-service</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-resource</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-foundation</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <!-- Servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.0.1</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.2</version> <scope>provided</scope> </dependency> <!-- jstl --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </dependencyManagement> </project>
test-hd-foundation中的依賴(lài)
<?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.hd</groupId> <artifactId>test-hd-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>test-hd-foundation</artifactId> <dependencies> <!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> <build> <plugins> <!-- define the project compile level --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>
test-hd-api中的依賴(lài)關(guān)系
<?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.hd</groupId> <artifactId>test-hd-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>test-hd-api</artifactId> <dependencies> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-foundation</artifactId> </dependency> <!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> <build> <plugins> <!-- define the project compile level --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> <finalName>test-hd-api</finalName> </build> </project>
test-hd-resource中的依賴(lài)關(guān)系
<?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.hd</groupId> <artifactId>test-hd-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>test-hd-resource</artifactId> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> <build> <plugins> <!-- define the project compile level --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> </build> </project>
test-hd-service中的依賴(lài)關(guān)系
<?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.hd</groupId> <artifactId>test-hd-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>test-hd-service</artifactId> <dependencies> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-foundation</artifactId> </dependency> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-api</artifactId> </dependency> <!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> <build> <plugins> <!-- define the project compile level --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> <finalName>test-hd-service</finalName> </build> </project>
test-hd-module中的依賴(lài)關(guān)系
<?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> <parent> <groupId>com.hd</groupId> <artifactId>test-hd-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>test-hd-modules</artifactId> <packaging>pom</packaging> <modules> <module>test-hd-www</module> <module>test-hd-admin</module> </modules> <dependencies> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-foundation</artifactId> </dependency> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-service</artifactId> </dependency> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-api</artifactId> </dependency> <dependency> <groupId>com.hd</groupId> <artifactId>test-hd-resource</artifactId> </dependency> <!-- servlet --> <dependency> <groupId>javax.servlet</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> </dependency> </dependencies> </project>
test-hd-www中的依賴(lài)關(guān)系
<?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.hd</groupId> <artifactId>test-hd-modules</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <artifactId>test-hd-www</artifactId> <packaging>war</packaging> <build> <plugins> <!-- define the project compile level --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins> <finalName>test-hd-www</finalName> </build> </project>
最后使用maven-update整個(gè)工程,右擊父工程名--》Maven--》Update Project
打包和發(fā)布
打包,右擊父工程名 test-hd-parent---->Run As--->Maven Install
打包web子工程,右擊工程名test-hd-www--->Run As ---> Maven Build...---> Goals: clean package--->Run
右擊工程名test-hd-www,進(jìn)行刷新,找到war包,放到tomcat的webapps中,啟動(dòng)tomcat,即可訪問(wèn)工程http://localhost:8080/test-hd-www
可以去tomcat下面webapps》test-hd-www》WEB-INF》lib中,看到引用的jar包
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。
網(wǎng)站名稱(chēng):詳解使用Maven構(gòu)建多模塊項(xiàng)目(圖文)
地址分享:http://chinadenli.net/article36/jgcssg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)、云服務(wù)器、手機(jī)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、企業(yè)建站、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
全網(wǎng)營(yíng)銷(xiāo)推廣知識(shí)