MAVEN仓库配置
2016-06-09 10:44
579 查看
1.两类仓库
1.1本地仓库(local repository)
可以自定义本地仓库的位置,修改${user.home}/.m2/settings.xml :
Xml代码
<settings>
...
<localRepository>D:\java\repository</localRepository>
...
</settings>
你还可以在运行时指定本地仓库位置:
mvn clean install -Dmaven.repo.local=/home/juven/myrepo/
1.2远程仓库(Remote repositories)
可以使用访问协议 such as file:// and http://. 运行maven所需jar包都是从本地仓库,引用在本地仓库没有时将触发从远处次仓库下载,并保存到本地。
2.Maven仓库概览
2.1 没有Maven仓库下的开发环境
2.2 具有团队内部远程仓库的开发环境
下面将就图2.2构建一个团队共享的maven repository
3.Maven仓库工具---Artifactory
3.1下载最新Artifactory,下面就我下载的Artifactory2.6.1配置作简单介绍。
1.双击artifactory.bat即可启动artifactory服务。访问地址http://localhost:8081/artifactory/可以看到服务的管理界面。
2.也可以在Tomcat部署Artifactory.
Startup the Servlet Container VM with -Dartifactory.home=$ARTIFACTORY_HOME,
pointing to the location of your Artifactory home folder (If you do not specify this property it will default to${user.home}/.artifactory).
Alternatively, you can also set an ARTIFACTORY_HOME environment variable to point to your Artifactory home folder.
Make Sure the folder is writable by the user running the Servlet Container.
Artifactory will try to create the folder on startup if it does not exist.
Make sure the Artifactory configuration file $ARTIFACTORY_HOME/etc/artifactory.config.xml and the log4j configuration file $ARTIFACTORY_HOME/etc/log4j.properties exist in their respective locations.
Deploy the artifactory.war file into the container.
3.2.maven的远程仓库地址设置
默认的远程仓库
我安装了maven-2.0.10,我可以找到这个文件:${M2_HOME}/lib/maven-2.0.10-uber.jar ,打开该文件,能找到超级POM:\org\apache\maven\project\pom-4.0.0.xml ,它是所有Maven POM的父POM,所有Maven项目继承该配置,你可以在这个POM中发现如下配置:
Xml代码
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
上为超级POM配置了ID为central的远程仓库,如果pom.xml中未配置仓库,默认的将使用这个central的超级仓库。
3.2.1在POM中配置远程仓库
使用artifactory在POM中配置其它的远程仓库。
[html] viewplain copy
<project>
.....
<repositories>
<repository>
<id>my-repo</id>
<name>my repository</name>
<url>http://localhost:8080/artifactory/my-repo/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>my-repo</id>
<name>my repository</name>
<url>http://localhost:8080/artifactory/my-repo/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<name>oss.sonatype.org</name>
<id>oss.sonatype.org</id>
<url>http://oss.sonatype.org/content/groups/public</url>
</pluginRepository>
</pluginRepositories>
...
</project>
3.2.2在settings.xml中配置远程仓库
除了在pox.xml配置仓库,setting文件可以作为一个全局的配置,但并不是简单的将POM中的<repositories>及<pluginRepositories>元素复制到settings.xml中就可以,setting.xml不直接支持 这两个元素。但我们还是有一个并不复杂的解决方案,就是利用profile,如下:Xml代码
<settings>
...
<profiles>
<profile>
<id>dev</id>
<!-- repositories and pluginRepositories here-->
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
</activeProfiles>
...
</settings>
这里我们定义一个id为dev的profile,将所有repositories以及pluginRepositories元素放到这个profile中,然后,使用<activeProfiles>元素自动激活该profile。这样,你就不用再为每个POM重复配置仓库。
3.3上传构件至远程仓库
我们需要配置POM的distributionManagement来指定Maven分发构件的位置,如下:Xml代码
<project>
...
<distributionManagement>
<repository>
<id>my-repo</id>
<name>Release Repository</name>
<url>http://localhost:8081/artifactory/my-repo</url>
</repository>
...
</project>
一般来说,分发构件到远程仓库需要认证,如果你没有配置任何认证信息,你往往会得到401错误。这个时候,如下在settings.xml中配置认证信息:
Xml代码
<settings>
...
<servers>
<server>
<id>my-repo</id>
<username>admin</username>
<password>password</password>
</server>
...
</settings>
需要注意的是,settings.xml中server元素下id的值必须与POM中repository或snapshotRepository下id的值完全一致。将认证信息放到settings下而非POM中,是因为POM往往是它人可见的,而settings.xml是本地的。
转自:
maven仓库配置
相关文章推荐
- 文章标题
- 3数据类型、数组、变量
- [MongoDB]索引
- 二分+树dp___zxa and leaf( hdu 5682 BestCoder Round #83 )
- actionbar以及制定
- 数据库之索引
- 使用Aspose组件将WORD、PDF、PPT转为图片
- ServletConfig与ServletContext对象详解
- 2编写一个简单的脚本
- UWP 入门系列资源集锦
- leetcode 18. 4Sum
- spring二次代理的问题
- 中断技术
- ServletContext作用功能详解
- poj 2406 Power Strings KMP的next数组的应用
- 1javascript语法
- WPF 启动类(窗口)移动到项目的子目录之后,无法启动程序,找不到xxx.xaml资源
- 编程之美2.41的数目Java版
- 基于JS如何实现类似QQ好友头像hover时显示资料卡的效果(推荐)
- 如何判断外设使用的地址空间