使用集成了maven的Eclipse版本新建maven項目后,配置文件pom.xml會在project以及引用的xsd文件處出現錯誤(第一、二行報錯)
其中一個報錯例子:
Multiple annotations found at this line:
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (execution: default-compile, phase: compile)
- CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:2.3.2 or one of its dependencies could not be resolved: Could not transfer?
artifact org.codehaus.plexus:plexus-compiler-javac:jar:1.8.1 from/to central (http://repo.maven.apache.org/maven2): connection timed out to http://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-compiler-javac/1.8.1/plexus-compiler-javac-1.8.1.jar
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (execution: default-testCompile, phase: test-compile) ??
等等報錯信息大同小異。
原因是:Eclipse集成的maven存在問題(版本問題或網站訪問問題),而新安裝的maven并未成功添加到m2e插件中
解決方法如下:
Step.1 到官網下載合適版本的maven 存放到合適的路徑(或者看報錯中缺少哪一個jar包文件----相應的報錯信息會提供網址取下載缺少的這個文件---copy到本地倉庫的相應路徑下)
Step.2 打開Eclipse的preferences->Maven->UserSettings 更改Global Settings和User Settings為剛剛下載的maven下的conf/settings.xml
Step.3?Eclipse的preferences->Maven->Installations 點擊Add添加剛才下載的maven文件夾,然后勾選自己下載的版本而不使用自帶版本
Step.4 經過以上兩步后,已經成功將自己下載的maven版本與Eclipse集成,這時右鍵點擊之前報錯的項目,右鍵 Run As ->Maven clean清理一下,再Run As ->Maven install即可
? ? ? Step.5(如果還不行):項目右擊->Maven->Update Project ? ?這一步需要一點時間,看界面的右下角就知道是否更新完。
?