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

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 dependencies for project com.kronos:spavpoc:jar:0.0.1-SNAPSHOT: Cannot access central (https://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 switch.[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 read the following articles:[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException


笔者发现自己的${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 2017sqljdbc4-4.0.pom>clojars-repo=sqljdbc4-4.0.jar>clojars-repo=


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


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

免责声明:本网信息来自于互联网,目的在于传递更多信息,并不代表本网赞同其观点。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,并请自行核实相关内容。本站不承担此类作品侵权行为的直接责任及连带责任。如若本网有任何内容侵犯您的权益,请及时联系我们,本站将会在24小时内处理完毕。
相关文章
返回顶部