Maven中如何解决Cannot access central in offline mode?

笔者在自己的一个项目中用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.xxx: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

 

 

笔者发现自己的${user.home}/.m2/repository 目录下的的确确也存在这个jar文件,那么为什么编译通不过呢?

后发现其里面有一个_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=

 

 

但是我的Maven的pom.xml已经把clojars-repo的repo删除掉了,是不是因为这个原因导致Maven的编译通不过呢?抱着尝试的心里,笔者删除了这个文件,再一次运行mvn clean verify, Awesome!!!! 通过了。

 

所以有的时候遇到问题一定换一种思维方式,多角度的尝试和分析,往往会有意想不到的收货。


 

 

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页