maven总结

来源:互联网 发布:政府网络危机公关案例 编辑:程序博客网 时间:2024/05/17 22:22

maven使用技巧


使用国内仓库

找到maven安装目录,打开conf/setting。xml文件,找到<mirrors>元素,给它增加一个<mirror>子元素如下:

<mirrors>    <!--增加的配置:国内maven库,配置于20150904-->    <mirror>      <id>CN</id>      <name>OSChina Central</name>                                                                                                                             <url>http://maven.oschina.net/content/groups/public/</url>      <mirrorOf>central</mirrorOf>    </mirror>  </mirrors>

更详细的教程看:开源中国 Maven 库使用帮助

更改本地maven库的位置

找到maven安装目录,打开conf/setting。xml文件,在<settings>元素下,增加一个<localRepository>子元素:

<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">  <!--增加的代码-->  <localRepository>D:\share\lib\maven\repository</localRepository>

出错处理


pom.xml文件突然出错

maven项目的pom.xml莫名其妙的出现错误(文件上有个叉叉),打开文件,里面的内容没有任何错(没有叉叉)

原因:很可能是某个版本没有,也就是groupidartifactid都正确,但是version找不到。

解决办法一:修改version的值

解决办法二:可以右键 JRE System Library , 进入Properties,然后换一个Execution environment,保存退出,然后再运行maven update就可以了。这个办法可以消除叉叉,但是不保证能解决问题。

某个依赖无法读取(can not be read)

Description Resource Path Location Type
Archive for required library: ‘D:/share/lib/maven/repository/junit/junit/4.12/junit-4.12.jar’ in project ‘mocktest’ cannot be read or is not a valid ZIP file mocktest Build path Build Path Problem

原因:很可能是限定了依赖的作用域导致的。比如下面的配置就可能出现上面错误:

    <dependency>      <groupId>junit</groupId>      <artifactId>junit</artifactId>      <version>4.8.2</version>      <scope>test</scope>    </dependency>

解决办法:把<scope>test</scope>去掉就可以了。

0 0