1.解决的问题
在idea中新创建了springboot项目,但pom中依赖的包总是无法导入。工作的网络不能直接访问外网,需要配置代理。
本地的maven已经做了配置,并把资料库改为了淘宝的。
需要把idea的默认maven改为本地maven。
2.本地maven配置
maven的安装和配置,不在赘述,见:
maven的配置文件:MAVEN_HOME\conf\settings.xml。关键内容如下:
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ${user.home}/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
<localRepository>D:\Maven\local-repo</localRepository>
<proxies>
<!-- proxy
| Specification for one proxy, to be used in connecting to the network.
|
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<username>proxyuser</username>
<password>proxypass</password>
<host>proxy.host.net</host>
<port>80</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
-->
<proxy>
<id>optional</id>
<active>true</active>
<protocol>http</protocol>
<host>********</host>
<port>80</port>
<nonProxyHosts>*******.com.cn</nonProxyHosts>
</proxy>
</proxies>
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<!--This sends everything else to /public -->
<id>nexus-aliyun</id>
<mirrorOf>*</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
3.设置idea的maven
Ctrl+Alt+s,【设置】,搜索maven:定位到【Build,Execution,Deployment】【Build Tools】【Maven】,【User setting file】,选定本地maven的配置文件。本地资料库会自动配置中的地址。
4.导入包检查效果
pom文件一修改,idea会自动提示是否导入,选择导入即可。
导入前【External Libraries】只有JDK的包,成功后,就有Maven自动导入的包了。