咱們用Eclipse建立Maven結構的web項目的時候選擇了Artifact Id爲maven-artchetype-webapp,項目上會有一個紅叉,打開目錄會發現src和web里根本沒有錯誤,並且程序還能正常執行,可是看着就是不爽,緣由是因爲這個catalog比較老,用的servlet仍是2.3的,而通常如今至少都是2.5,在Project Facets裏面修改Dynamic web module爲2.5的時候就會出現Cannot change version of project facet Dynamic web module to 2.5,如圖:html
其實在右邊能夠看到改到2.5須要的條件以及有衝突的facets,解決這個問題的步驟以下:java
1.把Servlet改爲2.5,打開項目的web.xml,改以前:web
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> </web-app>
改後:app
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <display-name>Archetype Created Web Application</display-name> </web-app>
2.修改項目的設置,在Navigator下打開項目.settings目錄下的org.eclipse.jdt.core.prefseclipse
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.source=1.5
把1.5改爲1.6webapp
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 org.eclipse.jdt.core.compiler.compliance=1.6 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.source=1.6
打開org.eclipse.wst.common.componentmaven
<?xml version="1.0" encoding="UTF-8"?> <project-modules id="moduleCoreId" project-version="1.5.0"> <wb-module deploy-name="test"> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <property name="context-root" value="test"/> <property name="java-output-path" value="/test/target/classes"/> </wb-module> </project-modules>
把project-version="1.5.0"改爲project-version="1.6.0"spa
<?xml version="1.0" encoding="UTF-8"?> <project-modules id="moduleCoreId" project-version="1.6.0"> <wb-module deploy-name="test"> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <property name="context-root" value="test"/> <property name="java-output-path" value="/test/target/classes"/> </wb-module> </project-modules>
打開org.eclipse.wst.common.project.facet.core.xmlcode
<?xml version="1.0" encoding="UTF-8"?> <faceted-project> <fixed facet="wst.jsdt.web"/> <installed facet="java" version="1.5"/> <installed facet="jst.web" version="2.3"/> <installed facet="wst.jsdt.web" version="1.0"/> </faceted-project>
把<installed facet="java" version="1.5"/>改爲<installed facet="java" version="1.6"/>,把 <installed facet="jst.web" version="2.3"/>改爲 <installed facet="jst.web" version="2.5"/>component
<?xml version="1.0" encoding="UTF-8"?> <faceted-project> <fixed facet="wst.jsdt.web"/> <installed facet="java" version="1.6"/> <installed facet="jst.web" version="2.5"/> <installed facet="wst.jsdt.web" version="1.0"/> </faceted-project>
都改好以後在打開看看,已經把Dynamic web module改爲了2.5
好了,大功搞成,這是一種解決辦法,若是還不行右鍵項目 > Maven > Update Project…