jetty-maven-plugin在eclipse中的使用

最近在eclipse使用jetty-maven-plugin的插件,以前也没有用过,今天发现这个插件很不错,使用很简单,就只需要配置一下文件就可以使用户了,不用户安装服务器,

并且在可以动态的部署java代码,js,css等所有的文件,大大的提高工作的效率。配置的步骤:

1. 当然是要安装maven,这里maven的安装就不做多的说明,比较简单 可以参考http://www.cnblogs.com/fnng/archive/2011/12/02/2272610.html

2. 安装完成后就开始在eclipse中建立一个maven项目

3. 主要修改的就是pom.xml文件,配置的jetty插件是最新的

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<packaging>war</packaging>

	<name>MavenLean</name>
	<groupId>MavenLean</groupId>
	<artifactId>MavenLean</artifactId>
	<version>0.0.1</version>

	<build>
		<plugins>
			<plugin>
				<groupId>org.mortbay.jetty</groupId>
				<artifactId>jetty-maven-plugin</artifactId>
				<version>8.1.9.v20130131</version>
				<configuration>
					<!-- 配置jetty的容器 端口等 -->
					<connectors>
						<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
							<port>8083</port>
							<maxIdleTime>30000</maxIdleTime>
						</connector>
					</connectors>
					<!-- 自动发现改变是时间,进行热部署,默认是0,不热部署 -->
					<scanIntervalSeconds>1</scanIntervalSeconds>
					<!-- 配置web容器 -->
					<webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
					<webAppConfig>
						<!-- 项目的根目录 -->
						<contextPath>/MavenLean</contextPath>
						<!-- <descriptor></descriptor> --> <!-- The path to the web.xml file for your webapp -->
						<defaultsDescriptor>src/main/resources/webdefault.xml</defaultsDescriptor>  <!-- webdefault.xml的路径,若没有配置就是用jetty默认,这个文件在web.xml加载之前加载 -->
					</webAppConfig>
					<reload>automatic</reload>   <!-- 自动部署默认是 automatic -->
					<systemProperties>
						<systemProperty>
							<name>org.mortbay.util.URI.charset</name>
							<value>UTF-8</value>
						</systemProperty>
					</systemProperties>
				</configuration>
			</plugin>
		</plugins>
	</build>

	<dependencies>
		<dependency>
			<groupId>servletapi</groupId>
			<artifactId>servletapi</artifactId>
			<version>2.4-20040521</version>
		</dependency>

		<dependency>
			<groupId>org.mortbay.jetty</groupId>
			<artifactId>jetty-maven-plugin</artifactId>
			<version>8.1.9.v20130131</version>
		</dependency>

	</dependencies>

</project>

 

4. 剩下的就是建立js html servlet进行测试

5. 最后说下eclipse怎么运行项目,一张图就可以说明


jetty-maven-plugin在eclipse中的使用_第1张图片

 

 

你可能感兴趣的:(maven)