原由:今天使用maven建立web項目的時候發現項目上總是有個紅X,錯誤以下圖所示,雖然項目能正常運行起來,可是LZ的強迫症發做,不弄掉就以爲內心不舒服,因而上網查了攻略,幾經周折最終大功告成,如今就把個人解決方法記錄下來,防止之後再次發生。java
解決步驟:web
1.打開web.xml文件apache
把頭部中2.3app
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd" id="WebApp_ID" version="2.3">
改成3.0eclipse
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
2.關閉eclipse 打開項目.settings目錄下的org.eclipse.jdt.core.prefswebapp
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.7maven
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.compliance=1.7
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.7
3.打開org.eclipse.wst.common.componentspa
<?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>
將1.5.0改成1.7.0code
<?xml version="1.0" encoding="UTF-8"?> <project-modules id="moduleCoreId" project-version="1.7.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>
4.打開org.eclipse.wst.common.project.facet.core.xmlcomponent
<?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>
將1.5改成1.7 2.3改成3.0
<?xml version="1.0" encoding="UTF-8"?> <faceted-project> <fixed facet="wst.jsdt.web"/> <installed facet="java" version="1.7"/> <installed facet="jst.web" version="3.0"/> <installed facet="wst.jsdt.web" version="1.0"/> </faceted-project>
此時從新打開eclipse,通常人到這個時候紅xx已經解決了,可是LZ打開一看紅x居然還在,心拔涼拔涼的,沒辦法,生活仍是要繼續,因而LZ又繼續找啊找,又被我找到個方法
5.在pom.xml中增長一段代碼
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.3</version> <configuration> <!-- 指定source和target的版本 --> <source>1.7</source> <target>1.7</target> </configuration> </plugin> </plugins>
此時紅x依舊在,哭死,感受生活沒了但願。最後右擊項目 Maven -> Update Project 紅x竟然消失了,真開心,雖然不知道什麼原理,可是先記錄一下,以防之後又出現這種請款。