maven3 + jetty 新建webapp

maven版本:apache-maven-3.3.3
eclipse插件版本:m2e - Maven Integration for Eclipse 1.4.1.20140328-1905


1. new-->maven project-->maven-archetype-webapp-->填写group_id,atifact_id-->finish
2. 创建完成后,结构如下
maven3 + jetty 新建webapp_第1张图片
3. 修改pom.xml,添加servlet dependency
    <dependency>    
        <groupId>javax.servlet</groupId>    
        <artifactId>servlet-api</artifactId>    
        <version>2.5</version>    
        <scope>provided</scope>    
    </dependency>


4. 添加maven的jetty插件
<plugins>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.2.8.v20150217</version>
        <configuration>
          <scanIntervalSeconds>10</scanIntervalSeconds>
          <httpConnector>
    		<port>8081</port>
  		  </httpConnector>
  		  
  		  <webApp>
          	  <contextPath>/${project.artifactId}</contextPath>
	          <!--
	          <resourceBases>
	            <resourceBase>${project.basedir}/src/main/webapp</resourceBase>
	            <resourceBase>${project.basedir}/commons</resourceBase>
	          </resourceBases>
	          -->
          </webApp>
        
  		  <requestLog implementation="org.eclipse.jetty.server.NCSARequestLog">
	          <filename>target/access-yyyy_mm_dd.log</filename>
	          <filenameDateFormat>yyyy_MM_dd</filenameDateFormat>
	          <logDateFormat>yyyy-MM-dd HH:mm:ss</logDateFormat>
	          <logTimeZone>GMT+8:00</logTimeZone>
	          <append>true</append>
	          <logServer>true</logServer>
	          <retainDays>120</retainDays>
	          <logCookies>true</logCookies>
          </requestLog>
        </configuration>
      </plugin>
    </plugins>


5.通过maven启动jetty
maven3 + jetty 新建webapp_第2张图片

6.访问 http://localhost:8081/springMybatis/
Hello World!

你可能感兴趣的:(maven3)