解決Cannot change version of project facet Dynamic web module to 2.5

咱們用Eclipse建立Maven結構的web項目的時候選擇了Artifact Id爲maven-artchetype-webapp,因爲這個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

,如圖 輸入圖片說明java

其實在右邊能夠看到改到2.5須要的條件以及有衝突的facets,解決這個問題的步驟以下: 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>

改以後:spring

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

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

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

<?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"webapp

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

<?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"/>code

<?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 輸入圖片說明 好了,大功搞成,這是一種解決辦法,可是治標不治本,更高級的就是自定義catalog,而後安裝到本地,再建立的時候啥都有了,好比把如今流行的s(struts2)sh,ssi,s(springmvc)sh 建立catalog,包括包結構,部分代碼啥的都有,下次寫吧。component

相關文章
相關標籤/搜索