由于每次项目启动的时候都会用tomcat,不是很方便。于是乎用了jetty插件。
首先依赖
<dependency> <groupId>org.eclipse.jetty.aggregate</groupId> <artifactId>jetty-all</artifactId> <version>9.0.0.v20130308</version> <type>jar</type> <scope>provided</scope> </dependency>
其次再引用:
<plugin> <groupId>org.eclipse.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>9.0.0.v20130308</version> <configuration><contextXml>${basedir}/src/main/resources/jetty-context.xml</contextXml> <scanIntervalSeconds>5</scanIntervalSeconds><httpConnector> <port>8080</port> </httpConnector> <webAppConfig> <contextPath>/admin</contextPath> </webAppConfig> </configuration></plugin>
但是这样子还不对,百度查了很多,发现还需要对jetty的服务器进行配置,本例中把配置文件放到了/src/main/resources中(如果你不希望打包时带上这个文件,可以放到/src/test/resources中,改下配置即可),文件名为:jetty-context.xml。接下来是配置文件:
<?xml version="1.0"?> <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> <Configure id="Server" class="org.eclipse.jetty.webapp.WebAppContext"> <Call name="setAttribute"> <Arg>org.eclipse.jetty.server.webapp.WebInfIncludeJarPattern</Arg> <Arg>.*/.*jsp-api-[^/]\.jar$|./.*jsp-[^/]\.jar$|./.*taglibs[^/]*\.jar$ </Arg> </Call> </Configure>
但是具体为什么要这么配,还没有具体的了解过。有需要的同学可以去研究一下。