普通web项目转化为maven web项目

1..configure ->Convert to Maven Project



2..maven添加jetty支持 ,并且修改webAppSourceDirectory

         <!--  添加jetty支持,Jetty 8 必须 Jdk 1.6+,Servlet 3.0,类似于 Tomcat 7-->

        <plugin>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>jetty-maven-plugin</artifactId>
          <version>8.1.16.v20140903</version>
          <configuration>
            <webAppSourceDirectory>${basedir}/WebContent</webAppSourceDirectory>
          </configuration>
        </plugin>



重要:maven项目webAppSourceDirectory默认为src/main/webapp对应于普通web项目的webcontent目录

mvn jetty:run-war  先打包,然后再部署(只打成war包的话也可以用mvn package命令)

mvn jetty:run -Djetty.port=80  默认端口也为8080


3.转换为maven项目jetty运行乱码问题(maven打包时候系统默认编码为 gbk)
pom.xml添加下面两个plugin
 <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>





${basedir} represents the directory containing pom.xml


4.添加junit依赖
 <dependencies>
  <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
     <version>4.11</version>
    </dependency>


  </dependencies>

5.添加服务器相关jar包

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>


6.添加json所需依赖(Jackson三个主要的模块:缺少这些jar包无法将对象转成json)

fasterxml为2.x(新版spring用的是这个)     1.x版本的包名是codehaus
<!--对象转json所需jar包  -->
    <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-core</artifactId>  
            <version>2.1.0</version>  
        </dependency>  
        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-databind</artifactId>  
            <version>2.1.0</version>  
        </dependency>  
        <dependency>  
            <groupId>com.fasterxml.jackson.core</groupId>  
            <artifactId>jackson-annotations</artifactId>  
            <version>2.1.0</version>  
        </dependency>
    

7.依赖jar包放在WebContent/WEB-INF/lib等目录下的情况

配置编译参数<compilerArguments>,添加extdirs将目录下的jar包相对路径添加到配置中,如下:

    <build>
        <plugins>
            <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <configuration>
                  <source>1.7</source>
                  <target>1.7</target>
                  <encoding>UTF-8</encoding>
                  <compilerArguments>
                   <extdirs>WebContent\WEB-INF\lib</extdirs>
                 </compilerArguments>
              </configuration>
            </plugin>
        </plugins>
    </build>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值