eclipse新建maven項目:'Building' has encountered a problem. Errors occurred during the build.



一、eclipse 新建maven 項目報錯(因為沒有配置maven環境)

1、問題:

① 出現的問題1:

Could not calculate build plan:Plugin
org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6

image


② 出現的問題2:

'Building' has encountered a problem. Errors occurred during the build.
image



2、分析問題:

① 錯誤原因:編譯工具eclipse沒有配置 maven的環境



3、解決:在eclipse中配置maven的環境

image


##### 3-1、又出現bug:
  • 報錯信息如下:
Description	Resource	Path	Location	Type
CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to collect dependencies at org.apache.maven.plugins:maven-compiler-plugin:jar:3.1 -> org.apache.maven.shared:maven-shared-incremental:jar:1.1 -> org.apache.maven:maven-core:jar:2.2.1 -> org.apache.maven:maven-profile:jar:2.2.1: ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.maven:maven-profile:jar:2.2.1: ArtifactResolutionException: org.apache.maven:maven-profile:pom:2.2.1 failed to transfer from http://maven.aliyun.com/nexus/content/groups/public during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of nexus-aliyun has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven:maven-profile:pom:2.2.1 from/to nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public): The operation was cancelled.	pom.xml	/ssm-xml-demo	line 6	Maven Project Build Lifecycle Mapping Problem

image

image

image


3-1、解決:在eclipse中強制更新maven的項目:快捷鍵 alt+f5,然后勾選 Force Update of Snapshots/Releases

image





二、補充一下 maven的環境搭建



Maven 環境搭建

一、准備工作:

1、maven下載:官網:https://maven.apache.org/download.cgi

  • 下載完成后解壓出來

2、配置環境變量

  • 細節:為什么要單獨配置一個M2_HOME 的變量:方便后續學習

    • 后續使用的自動依賴的系統,比如SpringBoot、SpringCloud,它會引用M2_HOME 這個地址。

■ 添加系統變量:

□ M2_HOME maven目錄下的bin目錄

□ MAVEN_HOME maven的目錄

□ 在系統的path中配置 %MAVEN_HOME%\bin

image-20220323174612772 image-20220323174737503

■ 驗證maven是否配置成功:查看maven版本的命令 mvn -version

image-20220323175147905

3、修改maven 配置文件的鏡像為 阿里雲鏡像

  • 配置文件位置:maven根目錄/conf/settings.xml 找到鏡像元素mirrors

  • 鏡像:mirrors:

    • 作用:加速下載
    • 默認是使用國外的鏡像,國內建議使用阿里雲鏡像加速下載
       <!-- 添加之前,先把原來的鏡像全注釋掉 -->
      <!-- 配置方式1 -->
       <mirror>
            <id>nexus-aliyun</id>
         <mirrorOf>*,!jeecg,!jeecg-snapshots</mirrorOf>
            <name>Nexus aliyun</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>
    
  <!-- 配置方式2 -->
	<mirror>
        <id>nexus-aliyun</id>
     <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>

4、修改maven 配置文件的本地倉庫位置

  • 修改本地倉庫位置為:maven 根目錄下 自己手動建立的 maven-repo
  • 配置文件位置:maven根目錄/conf/settings.xml 找到 localRepository元素
  <localRepository>E:\environment\mavenEvironment\apache-maven-3.8.2\maven-repo</localRepository>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM