Maven搭配webapp环境

1.首先在MyEclipse中new一个Maven项目。
在Archetype选项中选择
groupId->    org.apache.maven.archetypes
artifactId-> maven-archetype-webapp

2.导入Servlet API
	<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>servlet-api</artifactId>
			<version>2.5</version>
		</dependency>




3. 加入jetty容器
<build>
    <pluginManagement>
    	<plugins>
    		<plugin>
    			<groupId>org.mortbay.jetty</groupId>
					<artifactId>jetty-maven-plugin</artifactId>
					<version>8.1.0.RC5</version>
					<configuration>
						<scanIntervalSeconds>10</scanIntervalSeconds>
						<webApp>
							<contextPath>/hello</contextPath>
						</webApp>
						<connectors>
							<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
								<port>8888</port>
								<maxIdleTime>60000</maxIdleTime>
							</connector>
						</connectors>
						<stopPort>8898</stopPort>
						<stopKey>foo</stopKey>

					</configuration>
    		</plugin>
    	</plugins>
    </pluginManagement>
</build>



3. 右键pom.xml,选择run。

在goal命令行输入 jetty:run
如果服务正常启动,输入网址http://localhost:8888/hello,便可看到hello world!


4. 修改web.xml


<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
	id="WebApp_ID" version="2.5">

</web-app>


教程里说maven建立的schema是有问题的。 具体有什么问题我也不知道。反正照着做就是了。

猜你喜欢

转载自alleni123.iteye.com/blog/1983774