maven[tomcat/jetty]

Eclipse:

Base directory:${workspace_loc:project-name}
Goals:clean compile install -Dmaven.test.skip=true
Profiles:dev[对应pom.xml中的profile的ID]
User settings:自己选择
------------------------------------------------------------------------------
使用tomcat插件启动Web项目:
<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
        <port>8080</port>
        <path>/spider</path>
        <uriEncoding>UTF-8</uriEncoding>
        <finalName>spider</finalName>
        <server>tomcat7</server>
    </configuration>
</plugin>

mvn tomcat7:run
附加:不需配置插件,使用下边的是默认使用tomcat6版本
tomcat:run -Dmaven.tomcat.uriEncoding=UTF-8 -Dmaven.tomcat.path=/ -Dmaven.tomcat.port=8088
-------------------------------------------------------------------------------

使用jetty插件启动Web项目:jetty:run -Djetty.port=8088
添加项目源码: Source Tab Add  Java Project


Check $M2_HOME environment variable and mvn script match
解决:Maven=》Runner=>VM Options,填入
-Dmaven.multiModuleProjectDirectory=$M2_HOME

jetty插件:
取消文件映射缓存
    jetty 默认开启了 useFileMappedBuffer,在 jetty 运行期间,页面所使用的静态文件(如 css 文件等)不允许修改。如果你尝试去修改它们,保存的时候就会出现 Save could not be completed。
    解决办法,找到 %repo%/org/eclipse/jetty/jetty-webapp/9.2.8.v20150217/jetty-webapp-9.2.8.v20150217.jar,用压缩工具打开它, 找到 jetty-webapp-9.2.8.v2015021
7.jar/org/eclipse/jetty/webapp/webdefault.xml,将 webdefault.xml 文件解压缩一份出来,用文本编辑器打开它,搜索找到useFileMappedBuffer 配置的行,将 true 改成 false 以禁掉缓存。将原文件org/eclipse/jetty/webapp/webdefault.xml 删除,将刚才那份修改好的 webdefault.xml 文件重新压缩进去即可。
    当然我们可以复制出来一份放在项目源代码中,通过在插件中配置指定使用的webdefault.xml覆盖掉jar包中的,具体参见插件配置项:

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.2.8.v20150217</version>
      <configuration>
        <!-- 取消文件映射缓存指定的文件 -->
        <webDefaultXml>src/main/resources/webdefault.xml</webDefaultXml>
        <webAppSourceDirectory>src/main/webapp</webAppSourceDirectory>
        <!--
           对应-Djetty.scanIntervalSeconds=2启动项,表示热部署,默认0表示关闭,单位为秒;
           以配置数值为一个周期,自动的扫描文件检查其内容是否有变化,如果发现文件的内容被改变,则自动重新部署运用。
        <scanIntervalSeconds>3</scanIntervalSeconds>
        -->
        <contextPath>/</contextPath>
        <connectors>
          <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
            <port>8888</port>
          </connector>
        </connectors>
      </configuration>
    </plugin>
  </plugins>
</build>



mvn archetype:create -DgroupId=com.yy -DartifactId=sm -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

猜你喜欢

转载自903403246.iteye.com/blog/2369822