上一篇介绍了JavaEE Web应用的js css images html等如何模块化, 里面讲到使用overlays来依赖合并其它war包,但是使用中发现一个问题,如果你使用tomcat7-maven插件,使用tomcat7:run来运行的时候,依赖的那些war里面的文件并不能被访问到,换成tomcat7:run-war就可以,但是用run-war的话,就不能热部署了,在eclipse里面改一个jsp不能马上看到效果,要重新启动tomcat才行。
网上找了很多资料,发现都不行,最后想着换jetty-maven插件试试,结果一试果然jetty可以解决问题,详细配置请看
http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
最主要是下面这段,也就是说不需要特别的配置, jetty是支持多个war的,像我下面这样配置就可以了
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.3.7.v20160115</version>
<configuration>
<webApp>
<contextPath>/test</contextPath>
</webApp>
<httpConnector>
<port>8081</port>
</httpConnector>
</configuration>
</plugin>
Using Overlaid wars
If your webapp depends on other war files, thejetty:run and jetty:run-forked goals are able to merge resources from all of them. It can do so based on the settings of the maven-war-plugin, or if your project does not use the maven-war-plugin to handle the overlays, it can fall back to a simple algorithm to determine the ordering of resources.
The maven-war-plugin has a rich set of capabilities for merging resources. The jetty:run and jetty:run-forked goals are able to interpret most of them and apply them during execution of your unassembled webapp. This is probably best seen by looking at a concrete example.
Suppose your webapp depends on the following wars:
1
2
3
4
5
6
7
8
9
10
11
|
<
dependency
>
<
groupId
>com.acme</
groupId
>
<
artifactId
>X</
artifactId
>
<
type
>war</
type
>
</
dependency
>
<
dependency
>
<
groupId
>com.acme</
groupId
>
<
artifactId
>Y</
artifactId
>
<
type
>war</
type
>
</
dependency
>
|
Containing:
1
|