Jetty服务配置,Maven插件的方式使用。版本9.4.4.v20170414

在maven项目中的pom.xml中添加插件如下:

端口号:8090;项目访问路径:/

<build>
     <finalName>base</finalName>
	 <plugins>
		<!-- jetty插件 -->
		<plugin>
			<groupId>org.eclipse.jetty</groupId>
			<artifactId>jetty-maven-plugin</artifactId>
			<version>9.4.4.v20170414</version>
			<configuration>
				<httpConnector>
					<port>8090</port> <!-- 端口号 -->
				</httpConnector>
				<webApp>
					<contextPath>/</contextPath> <!-- 项目访问前缀 -->
				</webApp>
				<scanIntervalSeconds>10</scanIntervalSeconds>
			</configuration>
		</plugin>
		<!-- 项目版本号、jdk版本 -->
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-compiler-plugin</artifactId>
			<version>3.1</version>
			<configuration>
				<source>1.8</source>
				<target>1.8</target>
				<encoding>UTF-8</encoding>
			</configuration>
		</plugin>
	</plugins>
</build>

更新一下项目update project

然后,写一个简单的测试Controller

@RequestMapping(value = "/index", method = RequestMethod.GET)
public String index(String msg, Model model) {
	model.addAttribute("msg", msg);
	return "index";
}

index.jsp内容

好的,使用Goals启动项目:

右击项目:

配置Goals:jetty:run

如果需要加端口号(pom中端口号的优先级高):jetty:run -Djetty.port=8090

点击 Run启动项目服务

ok,测试一下

浏览器访问http://localhost:8090/index?msg=jetty

成功了,推荐一个朋友的公众号,有大量的技术文章哦

Guess you like

Origin blog.csdn.net/qq_36100599/article/details/82628427
Recommended