Maven中如何解決Cannot access central in offline mode?
阿新 • • 發佈:2018-12-15
筆者在自己的一個專案中用Maven進行編譯管理自己的一個專案,因為是沒有網路的環境的,所以筆者把Maven設定成了Offline模式,也就是直接使用本機Maven庫裡面的jar,而不是通過Internet從網上Maven倉庫中心獲取,其Maven的Setting.xml的檔案設定如下:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 https://maven.apache.org/xsd/settings-1.0.0.xsd"> <localRepository>${user.home}/.m2/repository</localRepository> <interactiveMode>true</interactiveMode> <usePluginRegistry>false</usePluginRegistry> <offline>true</offline> </settings>
其中用到了sqljdbc4的庫,
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>4.0</version>
</dependency>
但是,編譯的時候報了下面的錯誤,
[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.516 s [INFO] Finished at: 2017-08-30T05:25:11+08:00 [INFO] Final Memory: 19M/226M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project spavpoc: Could not resolve dependencie s for project com.kronos:spavpoc:jar:0.0.1-SNAPSHOT: Cannot access central (http s://repo.maven.apache.org/maven2) in offline mode and the artifact com.microsoft .sqlserver:sqljdbc4:jar:4.0 has not been downloaded from it before. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit ch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please rea d the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyReso lutionException
後發現其裡面有一個_remote.reposiories檔案,其內容如下,
#NOTE: This is an Aether internal implementation file, its format can be changed without prior notice. #Tue Mar 21 10:55:02 CST 2017 sqljdbc4-4.0.pom>clojars-repo= sqljdbc4-4.0.jar>clojars-repo=
所以有的時候遇到問題一定換一種思維方式,多角度的嘗試和分析,往往會有意想不到的收貨。