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!!!! 通过了。

 

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


 

 

  • 12
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值