前言: web開發 一直用tomcat ,maven 這個詞很熟悉一直沒用過,如今開始用maven構建一次工程。web
環境: jdk1.8 eclipse 4.6.1 maven3.3.9(jdk eclipse maven3.3.9安裝過程這裏不講解)apache
step1 : eclipse 下配置 maven : window-preferences-Maven-Installations-add 把maven加載進來tomcat
再進入User-Settings ,在User Settings(open file):裏引入maven的 settings.xmlapp
在maven安裝目錄下/conf/打開settings.xml,加入<localRepository>E:\workspaces\maven</localRepository> 這是maven加載組件的地方eclipse
step 2: 利用eclipse嚮導建一個maven工程maven
File-New-Other-Maven-Maven-Project 直接Next,出現ui
直接Next,出現this
選中 ...webpp 1.0 ,nexturl
Group Id 寫的包結構 com.xx ,Artifact Id寫上項目名稱就能夠,點 "Finish",一個項目就建好了.spa
setp 3:
項目會自動生成maven 的pom.xml,pom.xml以下
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.zw</groupId>
<artifactId>firstmaven</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>firstmaven Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>firstmaven</finalName>
</build>
</project>
maven根據pom.xml會自動加載須要的包,這時eclipse的狀態欄會顯示更新須要的jar, 這是一個漫長的過程,不少包是從國外的官方更新 ,效率很低. (我1秒更新不到1K,當時電腦開着更新了一夜,有一個更新卡住99%,還被我終止掉了,這可能致使了接下來的一個問題,後面會提到).
step4 :更新完後 pom.xml報一個錯誤:
在<packaging>war</packaging>
提示:Multiple annotations found at this line:
略去一大段的描述,有一個細節將問題定位在E:\Workspaces\maven\org\apache\maven\plugins\maven-resources-plugin\2.6\maven-resources-plugin-2.6.jar,好像就是剛纔更新99% 卡住那個包.
嘗試1: 把2.6下內容全刪掉,maven自動再更新,更新後無效。
嘗試2: 找資料解決一下,找到的資料:
一樣也是Multiple annotations found at this line:
It is not a unique issue, happens every now and then (sometimes due to a slow connection and sometimes due to proxy servers now allowing to download)
You can get rid of this by either of the following ways:
1) Force Update:Right Click on the Project in Eclipse -> Maven -> Update Project On this screen select the check box Force Update for Snapshots/Releases
2) Clearing Maven Cache:If you still face a problem, go to the local repository on your system, which might be present atC:\Users\myusername\.m2\repository
and delete the .cache folder and then follow step 1.
If still facing issues, manually go to the org/apache folder and delete everything and then follow step 1. (This will definitely solve the issue
按照資料顯示第一步第二步 force update 並 清了cache . 錯誤消失 。
資料的解釋緣由是:It is not a unique issue, happens every now and then (sometimes due to a slow connection and sometimes due to proxy servers now allowing to download)
正是我下載時出現的問題。
step 5 : 運行
eclipse -Run As- Maven... 直接Run
build faulire 報No goal錯誤,
<build>
<finalName>firstmaven</finalName>
</build>
加入 <defaultGoal>compile</defaultGoal>
<build>
<defaultGoal>compile</defaultGoal>
<finalName>firstmaven</finalName>
</build>
再Run一次,build successful!
Maven工程建完,先寫到這兒.