q989 发表于 2017-2-28 11:26:37

Maven 搭建环境(http://dearshor.javaeye.com/blog/272274)

Maven搭建环境

Maven + Artifactory
(Two Setting + One POM + Artifactory)
1)Artifactory

2)Two Setting

3)Pom


Question:如何从零开始完成一个项目(从部署和开发的角度)
1、maven的配置

1)、maven的配置必须建立在jdk1.4版本基础上,即必须先配置jdk环境。

2)、maven无须安装,从网上下载后,直接解压到本地就可以了。

3)、maven配置完毕后,用maven -version命令来检测是否安装成功。

2、maven的settings.xml修改

1)、在<localrespository>...</localrespository>标签中设置本地的版本库路径,例如<localrespository>d:/repo</localrespository>

本地版本库用来存放你从远端版本库中下载的jar包。路径可以是空的文件夹,必须要存在。如果不设置,那么maven默认为.m2/respository的路径。

2)、如果机器能够上网,那么无须配置代理,如果须代理上网的话,必须配置<proxy>..</proxy>,例如:

    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username></username>
      <password></password>
      <host></host>
      <port></port>
   nonProxyHosts>local.net,some.host.com</nonProxyHosts>
    </proxy>

3)、如果需要从局域网内访问本地服务器上的版本库,那么可以设置<mirror>…</mirror>,例如

<mirror>

   <id>planetmirror.com</id>

   <name>test</name>

   <url>…. </url>

   <mirrorOf>central</mirrorOf>

   </mirror>

注意<url>…. </url>里填写你服务器的访问地址,这里地址可以用apache或者tomcat来做为你的中心版本库的应用。

<mirrorOf>central</mirrorOf>中必须写成central。
==================================================================================================
配置Actifactory (Configuration) - 安装目录的etc下有3个配置文件jetty.xml,log4j.properties,artifactory.config.xml,通过文件名我们就已经知道它们的用途了。如果Actifactory服务器不能直接上网,而需HTTP代理的话需打开配置文件的proxies一项,并配置相应的 HTTP代理,配置好后将proxy的key添加到<remoterepository>节点的 <proxyref>中,注意配置完成后需在控制台中Reload Configuration一下。eg:</proxyref> </remoterepository>
xml 代码
# <proxies>
#   <proxy>
#         <key>seraph-proxykey>
#         <host>192.168.1.1host>
#         <port>80port>
#         <username>username>
#         <password>password>
#         <domain>192.168.1.255domain>
#   proxy>
# proxies>
#   
#   <remoteRepository>
#         <key>repo1key>
#         <handleReleases>truehandleReleases>
#         <handleSnapshots>falsehandleSnapshots>
#         <excludesPattern>org/artifactory/**,org/jfrog/**excludesPattern>
#         <url>http://repo1.maven.org/maven2url>
#         <proxyRef>seraph-proxyproxyRef>
#   remoteRepository>
配置Maven (Setting Up Maven) - 接下来配置maven。将以下配置项配置好后添加到maven的settings.xml或pom.xml中,即可使用搭建起来的maven本地服务器了
xml 代码
   1.<repositories>
   2.   <repository>
   3.         <id>central</id>
   4.         <url>http://:/artifactory/repo</url>
   5.         <snapshots>
   6.             <enabled>false</enabled>
   7.         </snapshots>
   8.   </repository>
   9.   <repository>
10.         <id>snapshots</id>
11.         <url>http://:/artifactory/repo</url>
12.         <releases>
13.             <enabled>false</enabled>
14.         </releases>
15.   </repository>
16. </repositories>
17. <pluginRepositories>
18.   <pluginRepository>
19.         <id>central</id>
20.         <url>http://:/artifactory/plugins-releases</url>
21.         <snapshots>
22.             <enabled>false</enabled>
23.         </snapshots>
24.   </pluginRepository>
25.   <pluginRepository>
26.         <id>snapshots</id>
27.         <url>http://:/artifactory/plugins-snapshots</url>
28.         <releases>
29.             <enabled>false</enabled>
30.         </releases>
31.   </pluginRepository>
32. </pluginRepositories>
然后mvn下,就可以看到Actifactory在响应你的请求,控制台中也可看到Repositories Tree中的jar越来越多了。
页: [1]
查看完整版本: Maven 搭建环境(http://dearshor.javaeye.com/blog/272274)