Eclipse配置maven web项目问题总结

clipse创建Maven结构的web项目的时候选择Artifact Id为maven-artchetype-webapp,点击finish之后,一般会遇到如下问题

1. The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path 错误,

   这是eclipse环境里没有SeverRuntime导致的,在BuildPath里加入即可,如下图:

   添加前:

    

   选择 add library

     

   选择 Apache Tomcat V7.0 并点击 next

   

   点击finish之后,完成添加如下图

 

 

2. 如何Maven创建动态Web项目后产生的版本不匹配的问题

   我们用Eclipse创建Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,由于这个catalog比较老,用的servlet还是2.3的、java版本是1.5的,而一般现在至少都是3.0/1.7,因此我们需要逐个修改!

    (1) 修改JRE 版本

    Go to project Build Path and change the Java Library version to 1.7

删除原先的低版本JRE,并添加workplace默认的版本(JDK1.7),完成后如下:

(2) Eclipse Preferences -> Java -> Compilre -> Change compliance level to 1.7

(3) 修改 Project Facets 版本(注意顺序)

    在项目上单机右键 -> Properties -> Project Facets  -->取消选中 Dynamic Web Module 状态,点击 Apply -->将 Java facet 版本变为 1.7 ,点击 Apply如下图

 -->将 Dyanmic Web Module 版本更改为3.0, 点击 Apply.

此时会有较大几率提示: web.xml is missing and <failOnMissingWebXml> is set to true,如下图

解决办法,在项目上单击右键-->java EE Tools ---> Generate Deployment Descriptro Stub

OK 问题解决

3. 解决发布之后404错误

默认情况下因为默认的deployment assembly中 webapp路径的问题,如下图可以看到默认的webapp下的页面都被发布到WEB-INF/class下了,

导致出现了如下图的目录结构,所以所有的jsp都无法访问以及通过web.xml加载的ssm环境无法初始化!

 

警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source'

出现SetPropertiesRule警告的原因是因为Tomcat在server.xml的Context节点中不支持source属性:<Context docBase="…" path="/…" source="org.eclipse.jst.j2ee.server:…"/>

解决方法是在Servers视图里双击创建的server,然后在其server的配置界面中选中"Publish module contexts to separate XML files"选项。


具体“Publish module contexts to separate XML files”是什么意思,

请看Tomcat Publishing Options介绍:


Two new options which affect publishing are now available in the Server Options section of the Tomcat server editor. The Tomcat server must be 5.0.x or later for these options to be enabled. The Serve modules without publishing option does what it says. Web content will be served directly from the "WebContent" folder of the Dynamic Web Project. A customized context is used to make the project's dependencies available in the Web application's classloader. The Publish module contexts to separate XML files option will publish contexts using the preferred method of separate XML files under the "conf/Catalina/localhost" directory, rather than keeping them in the "server.xml" file. A couple of improvements for this option are noted in Bugs 180931 and 180936.

关于解决方法,再详细说明一下:

Servers视图的打开方法:Window--Show View-other..--Servers

双击Server:就是双击服务器名,我的服务器名为:Tomcat v6.0 Server at localhost 即双击它,进入

server的配置界面: 选中"Publish module contexts to separate XML files"选项

 

web.xml is missing and <failOnMissingWebXml> is set to true解决方法

这种错误是因为maven默认简单构建项目是sevlet3.0版本,web.xml不是必须的,这时候需要手动创建webapp/WEB-INF/web.xml,web.xml可以从其他项目复制一个过来改改, 
或者pom.xml添加如下配置

<build>
    <pluginManagement>
        <plugins>
            <plugin>  
                <groupId>org.apache.maven.plugins</groupId>  
                <artifactId>maven-war-plugin</artifactId>  
                <configuration>  
                    <failOnMissingWebXml>false</failOnMissingWebXml>  
                </configuration>  
            </plugin> 
        </plugins>

    </pluginManagement>
</build>

修改完了别忘了右键项目Mavan/update project..

转载于:https://my.oschina.net/u/3470396/blog/1611205

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值