Eclipse配置maven web项目问题总结

clipse建立Maven结构的web项目的时候选择Artifact Id为maven-artchetype-webapp,点击finish以后,通常会遇到以下问题java

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

   这是eclipse环境里没有SeverRuntime致使的,在BuildPath里加入便可,以下图:apache

   添加前:服务器

    

   选择 add libraryapp

     

   选择 Apache Tomcat V7.0 并点击 nexteclipse

   

   点击finish以后,完成添加以下图webapp

 

 

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

   咱们用Eclipse建立Maven结构的web项目的时候选择了Artifact Id为maven-artchetype-webapp,因为这个catalog比较老,用的servlet仍是2.3的、java版本是1.5的,而通常如今至少都是3.0/1.7,所以咱们须要逐个修改!maven

    (1) 修改JRE 版本ui

    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..

相关文章
相关标签/搜索