maven系列之-多模塊多Web應用合併War包

maven 多模塊多Web應用合併War包是根據我上一章的分模塊分工程管理的內容基礎之上來寫的,如果要看這部分內容需要結合上一章“maven 分模塊分工程管理”來着手。

我這個工程分爲一個頂級父工程和五個子級模塊工程,項目都已經成功的建立了。

我這會要將客戶管理customermgr項目以及goodsmgrweb項目合併到architectureweb中並且在相應的項目中新建jsp,文件以及對應的js文件,並且會分別單獨運行customermgr、goodsmgrweb、architectureweb模塊,看看maven的分模塊分工程管理的方便之處。

1.architectureweb要配置好customermgr、goodsmgrweb的相關依賴。

代碼:

 

<dependencies>
		<dependency>
			<groupId>com.hxqc</groupId>
			<artifactId>customermgr</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>war</type>
		</dependency>
		<dependency>
			<groupId>com.hxqc</groupId>
			<artifactId>goodsmgrweb</artifactId>
			<version>0.0.1-SNAPSHOT</version>
			<type>war</type>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>
	<build>
		<finalName>architectureweb</finalName>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.0.0</version>
				<configuration>
					<overlays>
						<overlay>
							<groupId>com.hxqc</groupId>
							<artifactId>customermgr</artifactId>
						</overlay>
						<overlay>
							<groupId>com.hxqc</groupId>
							<artifactId>goodsmgrweb</artifactId>
						</overlay>
					</overlays>
				</configuration>
			</plugin>

 

 

 

 

 

2.在common公共資源模塊新建java class Base1然後在customermgr中調用Base1的方法看看合併效果。

3.在customermgr中新建customer1類然後寫入一個方法,在customermgr新建其他的jsp文件、文件夾、js並且寫入相關的方法輸出。文件太多反鎖就不一 一展示就是每個js或者jsp文件寫個能輸出的方法主要看效果用。

在jsp文件中調用common中的base1類中的方法時要早customermgr中注入common依賴關係,不然引用import base1類時會報錯。

4.商品後臺管理goodsmgr項目中新建goods1類在goodsmgrweb中調用看合併依賴效果。

5.商品管理goodsmgrweb頁面管理,在這裏面類似於customermgr新建js、jsp文件在文件中輸入一些輸出做觀察用項目結構如圖。

由於在goodsmgrweb 的jsp頁面中調用了goodsmgr 裏面的goods類以及裏面的方法,所以也要在goodsmgrweb注入goodsmgr不然jsp文件會報錯。

6.總項目architecture右鍵--->run as--->maven install architecturex項目結構如下。

根據目錄會發現子模塊有重複部分的a.jsp文件合併的時候只取了一個,這裏我們是按照配置依賴的時候的順序來取的。

所以在分模塊管理項目中要區別的對待新建的各種文件,避免重複的同路徑同文件名。

7.運行項目舉例goodsmgrweb項目的運行,architectureweb、customermgr運行類似不一 一舉例。

首先,配置goodsmgrweb pom.xml 文件加入jetty插件配置。

 

<plugins>
	<plugin>
		<groupId>org.mortbay.jetty</groupId>
		<artifactId>jetty-maven-plugin</artifactId>
		<version>8.1.16.v20140903</version>
		<configuration>
			<scanIntervalSeconds>10</scanIntervalSeconds>
			<stopPort>9999</stopPort>
			<webApp>
				<contextPath>/goods</contextPath>
			</webApp>
		<connectors>
			<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
			        <port>9080</port>
			        <maxIdleTime>60000</maxIdleTime>
			</connector>
			<!-- <connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector"> 
			<port>9443</port> <password>changeit</password> </connector> -->
			</connectors>
		</configuration>
	</plugin>
</plugins>

 

 

 

右鍵goodsmgrweb ---> run as --->run configurations (jetty:run)

運行成功就會出現:

 

[INFO] Classes = D:\Workspaces\architecture\goodsmgrweb\target\classes
[INFO] Context path = /goods
[INFO] Tmp directory = D:\Workspaces\architecture\goodsmgrweb\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:/D:/Workspaces/architecture/goodsmgrweb/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = D:\Workspaces\architecture\goodsmgrweb\src\main\webapp
[INFO] jetty-8.1.16.v20140903
[INFO] No Transaction manager found - if your webapp requires one, please configure one.
[WARNING] !RequestLog
[INFO] Started [email protected]:9080
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 10 seconds.


然後訪問效果如下:

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章