maven项目配置jetty

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/shelbyandfxj/article/details/79574551

在maven项目的pom.xml中配置如下(格式化不了,将就着看吧):

<plugins>
			<plugin>
				<groupId>org.eclipse.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>9.4.5.v20170502</version>
				<configuration>
					<scanIntervalSeconds>10</scanIntervalSeconds>
					<httpConnector>
						<port>8080</port>
					</httpConnector>
					<webApp>
						<contextPath>/bucket</contextPath>
					</webApp>
				</configuration>
			</plugin>
		</plugins> 

配置完上一步之后,以为已经搞定直接运行项目的时,又报错误了,提示我“程序包javax.servlet不存在”,原因是servlet-api包在tomcat下面是自带的,但在jetty中是没有的,因此在jetty的配置中药加上这个依赖,如下面的配置:

<dependency>
			<groupId>org.apache.geronimo.specs</groupId>
			<artifactId>geronimo-servlet_2.4_spec</artifactId>
			<version>1.1.1</version>
			<scope>provided</scope>
		</dependency>

好了,经过上面的配置后可以运行了,补充一下怎么运行吧,右击项目->Run As->Maven build...->Gloas一栏敲上 jetty:run就可以运行了。

在运行的时候呢,发现为什么每次运行的时候,都会重新去下载依赖呢,之前不是下载过了么,有人告诉我,可能是maven的setting.xml的仓库地址问题,果然,因为刚刚这个setting.xml是从网上拉下来的,那个地址还没改,把它改为本地的下次就不会重新下载依赖了。


猜你喜欢

转载自blog.csdn.net/shelbyandfxj/article/details/79574551