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.
然后访问效果如下: