1、概述css
上一篇文章介绍了Jenkins结合svn来构建jar包,本文介绍另外一种代码提交的方式git,并结合maven来构建代码包。java
实验环境:linux
IP: 10.0.90.27 系统: Centos6.6 x86_64
软件包:
git
Jenkins 2.9 Tomcat 8.0.36 JDK 8.92 maven 3.3.9 git
2、安装步骤
web
一、安装jdkspring
#rpm -ivh jdk-8u92-linux-x64.rpm Preparing... ########################################### [100%] 1:jdk1.8.0_92 ########################################### [100%] Unpacking JAR files... tools.jar... plugin.jar... javaws.jar... deploy.jar... rt.jar... jsse.jar... charsets.jar... localedata.jar...
二、安装tomcatapache
#tar xf apache-tomcat-8.0.36.tar.gz -C /usr/local/ #cd /usr/local/ #ln -sv apache-tomcat-8.0.36 tomcat 启动 #cd tomcat #./bin/startup.sh Using CATALINA_BASE: /usr/local/tomcat Using CATALINA_HOME: /usr/local/tomcat Using CATALINA_TMPDIR: /usr/local/tomcat/temp Using JRE_HOME: /usr Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar Tomcat started. 访问测试: 在浏览器输入http://10.0.90.27:8080,出现tomcat的默认网页,表示安装成功。
三、安装Jenkins(安装方式是直接解压到tomcat中)bootstrap
将jenkins.war包拷贝的/usr/local/tomcat/webapps目录api
而后再浏览器访问:浏览器
http://10.0.90.27:8080/jenkins/ 显示下面界面
根据提示从/root/.jenkins/secrets/initialAdminPassword文件中获取密码,而后继续,会看到以下界面:
而后就按照默认的选择(Install suggested plugins),继续下一步,会看到安装Plugin的界面:
安装Plugin的过程会花费一些时间,请耐心等待……
PS:若是一直处于安装状态(可能会由于网络缘由,有些个Plugin安装不了),能够刷新一下浏览器,若是刷新以后提示你安装失败,你能够点击提示的“Retry”,继续。安装好Plugin以后,会让你建立一个admin用户,你能够自定义以下图:
也能够继续使用admin用户,以下红方框中的按钮(我这里是建立了一个普通的admin用户liguang):
建立好以后,点击“Save and Finish”按钮,会弹出以下页面:
而后点击 “Start using Jenkins”,就会看到安装好的Jenkins界面了
能够查看以前安装了哪些插件,哪些安装成功了,哪些没有安装成功,方法:“系统管理”--“管理插件”,会看到插件的界面,能够根据状况操做。
注意:假如你想使用svn来管理代码,可是svn插件没有安装,就会在建立的新项目进行配置的时候,“代码管理”设置部分显示为None,以下:
这个时候,你就须要安装svn插件了。
四、Jenkins安装插件
“系统管理”--“管理插件”--“可选插件”,而后在右上角的“过滤”长方框中输入svn,就会看到不少svn相关的插件,选择安装以下的插件便可:
选择“直接安装”或者“下载待重启后安装”均可以,我这里选择第二个,而后会看到以下界面,先是处于“等待”的状态,过一下子就是“安装中”的状态。
安装好以后,提示以下图:
而后从新启动tomcat,刷新浏览器,再到“插件管理”查看svn的安装状况,以下表示安装成功:
PS:这时,在到test_app项目中的“源码管理”部分,就会看到“None”和“Subversion”都存在了!可是不少时候咱们也会用到CVS或者git来拉取代码,因此须要安装这2个插件。安装CVS(CVS Plug-in)和git(Git plugin)插件,方法同样,须要重启tomcat生效,安装完成以后,在项目配置的时候,就能够看到了,以下:
这样就有4种方式进行源码的管理了!
五、查看Jenkins的Global Tool Configuration
“系统管理”---“Global Tool Configuration”,以下图:
根据提示能够看出是Jenkins服务器没有安装git,找不到git命令,后面会介绍安装git的方式。
3、配置Jenkins经过git拉取代码
注:gitlab的安装配置这里不介绍了(若是和Jenkins安装到同一台服务器,须要注意端口不要冲突了)
一、在Jenkins服务器生成key
#ssh-keygen -t rsa ##不须要设置密码,一路回车便可 Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 5a:f1:2f:5c:78:26:26:0d:a4:43:e7:bf:c8:a0:91:e9 root@localhost.localdomain The key's randomart p_w_picpath is: +--[ RSA 2048]----+ | . o | | . = | | o + | | o . * . | | + . S B + | | . o = = B | | E . o + . | | . | | | +-----------------+
二、在Jenkins服务器安装git客户端命令,我这里直接yum安装
#yum install git -y 查看版本: #git --version git version 1.7.1
安装好以后,再到Global Tool Configuration查看,就不会有二.5提示的错误了。顺便为其设置一个名称,Name 设置为git1.7.1 ,Path to Git executable 保持不变便可。
三、查看gitlab上Project的信息(我这里用的是以前搭建好的gitlab,地址是10.0.18.173),这里以server1/CSS项目为例:
红方框中给出的是访问该代码的方式,咱们用的是git,因此须要配置为git@10.0.18.173:server1/css.git,也能够是域名:git@git.test111.com:server1/css.git
四、在Jenkins的项目中配置,以test_app为例子,
不过配置好以后,遇到了以下的问题:
缘由:根据错误提示,发现是没有权限到gitlab服务器端拉取代码,须要将Jenkins服务端刚才生成的id_rsa.pub配置在某一个能够登陆gitlab用户的SSH Keys 中,方法以下:
使用一个用户登陆到gitlab,而且这个用户对gitlab上的全部项目有读写权限,而后添加Jenkins的key
点击右上方的“Profile settings”,在弹出的页面再点击“SSH Keys”,会弹出以下界面:
点击“Add SSH Key”,自定义Title,将key粘贴到下面的方框中,点击“Add key”,以下图:
而后刷新Jenkins页面,上面三.4出错的页面,就不会再报错了!
PS:若是安装好Jenkins以后,你配置了普通用户而且设置了邮箱,添加好key以后,系统会发邮件通知你,内容以下:
五、为项目添加代码分支
首先要从gitlab上查看代码分支,而后在Jenkins的每一个项目中添加分支,以test_app项目为例子,以下:
添加好以后要apply和save!
PS:每次构建只能配置一个分支!
六、其余配置:
能够配置丢弃旧的构建,由于保留太多没有用。
4、配置Jenkins经过maven打包代码
一、安装maven插件,名称为:Maven Integration plugin,以下:
而后点击“直接安装”,须要等一些时间才能安装完成,而后重启tomcat生效!
PS:安装的时候遇到一个问题,安装3次都不成功,提示失败,以下图:
而后ping域名updates.jenkins-ci.org是不通的,而后换用浏览器访问http://ftp.yz.yamagata-u.ac.jp/pub/misc/jenkins/plugins/maven-plugin/2.13/是能够访问的,而后我反复尝试了5-6次,最后安装成功了,无解!!!
二、在Jenkins上安装maven
#tar xf apache-maven-3.3.9-bin.tar.gz -C /usr/local/ #cd /usr/local/ # ln -sv apache-maven-3.3.9/ maven `maven' -> `apache-maven-3.3.9/' 设置环境变量 #vi /etc/profile #在末尾添加 ##maven MAVEN_HOME=/usr/local/maven export MAVEN_HOME export PATH=${PATH}:${MAVEN_HOME}/bin 执行source,使设置生效 #source /etc/profile 查看安装maven的信息 #mvn -v Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) Maven home: /usr/local/maven Java version: 1.8.0_92, vendor: Oracle Corporation Java home: /usr/java/jdk1.8.0_92/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "2.6.32-504.el6.x86_64", arch: "amd64", family: "unix"
在Jenkins的web界面配置Maven版本和路径,选择“系统管理”--“Global Tool Configuration”,配置为以下:
而后“Apply”--“Save”
三、使用Maven建立项目
不管是学习语言仍是框架,先来一个Hello World基本上已是套路了,这里也经过构建一个Hello World项目来了解如何使用Maven。
a、首先经过maven建立helloworld项目
#mvn archetype:create -DgroupId=helloworld -DartifactId=helloworld [INFO] Scanning for projects... Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom (4 KB at 0.2 KB/sec) Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-plugins/22/maven-plugins-22.pom (13 KB at 2.0 KB/sec) Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/21/maven-parent-21.pom Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/maven-parent/21/maven-parent-21.pom (26 KB at 6.1 KB/sec) Downloading: https://repo.maven.apache.org/maven2/org/apache/apache/10/apache-10.pom Downloaded: https://repo.maven.apache.org/maven2/org/apache/apache/10/apache-10.pom (15 KB at 6.7 KB/sec) Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.jar (25 KB at 6.5 KB/sec) ……………… ##省略 Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-archetype-plugin/2.4/maven-archetype-plugin-2.4.jar (92 KB at 2.3 KB/sec) [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-archetype-plugin:2.4:create (default-cli) @ standalone-pom --- Downloading: ……………… ##省略 Downloaded: https://repo.maven.apache.org/maven2/org/codehaus/groovy/groovy/1.8.3/groovy-1.8.3.jar (5394 KB at 7.3 KB/sec) [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 27:02 min [INFO] Finished at: 2016-06-21T19:04:30+08:00 [INFO] Final Memory: 12M/30M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.4:create (default-cli) on project standalone-pom: Unable to parse configuration of mojo org.apache.maven.plugins:maven-archetype-plugin:2.4:create for parameter #: Cannot create instance of interface org.apache.maven.artifact.repository.ArtifactRepository: org.apache.maven.artifact.repository.ArtifactRepository.<init>() -> [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/PluginConfigurationException 能够看到,是有ERROR出现,google寻找缘由,说法不一,而后尝试了以下方式: 缘由:archetype:create命令已通过期,须要使用 archetype:generate 来进行代替 #mvn archetype:generate -DgroupId=helloworld -DartifactId=helloworld [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> maven-archetype-plugin:2.4:generate (default-cli) > generate-sources @ standalone-pom >>> [INFO] [INFO] <<< maven-archetype-plugin:2.4:generate (default-cli) < generate-sources @ standalone-pom <<< [INFO] [INFO] --- maven-archetype-plugin:2.4:generate (default-cli) @ standalone-pom --- [INFO] Generating project in Interactive mode ……………… ##信息太多,省略 ……………… 1611: remote -> uk.co.solong:angular-spring-archetype (So Long archetype for RESTful spring services with an AngularJS frontend. Includes debian deployment) 1612: remote -> us.fatehi:schemacrawler-archetype-maven-project (-) 1613: remote -> us.fatehi:schemacrawler-archetype-plugin-command (-) 1614: remote -> us.fatehi:schemacrawler-archetype-plugin-dbconnector (-) 1615: remote -> us.fatehi:schemacrawler-archetype-plugin-lint (-) Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 799: Choose org.apache.maven.archetypes:maven-archetype-quickstart version: 1: 1.0-alpha-1 2: 1.0-alpha-2 3: 1.0-alpha-3 4: 1.0-alpha-4 5: 1.0 6: 1.1 Choose a number: 6: Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.jar (7 KB at 3.7 KB/sec) Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/archetypes/maven-archetype-quickstart/1.1/maven-archetype-quickstart-1.1.pom (2 KB at 4.1 KB/sec) [INFO] Using property: groupId = helloworld [INFO] Using property: artifactId = helloworld Define value for property 'version': 1.0-SNAPSHOT: : ##执行到此处中止了,回车便可 [INFO] Using property: package = helloworld Confirm properties configuration: groupId: helloworld artifactId: helloworld version: 1.0-SNAPSHOT package: helloworld Y: : ##输入Y,回车 [INFO] ---------------------------------------------------------------------------- [INFO] Using following parameters for creating project from Old (1.x) Archetype: maven-archetype-quickstart:1.1 [INFO] ---------------------------------------------------------------------------- [INFO] Parameter: basedir, Value: /root [INFO] Parameter: package, Value: helloworld [INFO] Parameter: groupId, Value: helloworld [INFO] Parameter: artifactId, Value: helloworld [INFO] Parameter: packageName, Value: helloworld [INFO] Parameter: version, Value: 1.0-SNAPSHOT [INFO] project created from Old (1.x) Archetype in dir: /root/helloworld [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 11:33 min [INFO] Finished at: 2016-06-22T10:03:37+08:00 [INFO] Final Memory: 14M/49M [INFO] ------------------------------------------------------------------------ b、在当前目录查看helloworld项目生成的目录,以下: #tree helloworld/ helloworld/ ├── pom.xml └── src ├── main │ └── java │ └── helloworld │ └── App.java └── test └── java └── helloworld └── AppTest.java 7 directories, 3 file
其中src/main/java是源码目录,src/test/java是测试文件目录,到这些目录能够看到App.java中已经写好了一个Hello World程序,而AppTest中是Junit单元测试的代码,至于pom.xml,则给出了项目的一些基本信息以及依赖关系。
看一下App.java和AppTest.java内容:
#cat App.java package helloworld; /** * Hello world! * */ public class App { public static void main( String[] args ) { System.out.println( "Hello World!" ); } } #cat AppTest.java package helloworld; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; /** * Unit test for simple App. */ public class AppTest extends TestCase { /** * Create the test case * * @param testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** * @return the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); } }
再看一下pom.xml文件
#cat pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>helloworld</groupId> <artifactId>helloworld</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>helloworld</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project>
解释:在pom.xml文件中,首先描述了项目的定义,groupId:artifactId:version:packaging这个四元组可以惟一标记一个项目。咱们不只能够用这个四元组来标记咱们的项目,也能够用来标记其它的项目,好比用来描述项目依赖关系。properties中定义了项目的属性,也能够在这里定义变量并在其它的地方引用。至于最后的dependencies,则是描述了项目的依赖关系,Maven会根据依赖关系自动下载相应的文件并在编译时使用。在大型项目开发中,每每会将其分红若干个子项目,每一个子项目都有着本身的的pom.xml,它们与父pom.xml之间至关于继承的关系。能够说,pom.xml文件的配置是整个Maven的核心重点,也是学习Maven过程当中须要详细了解的内容。这里只给出了最简单的配置样例,详细了解能够查看官方文档。
c、编译并运行helloworld项目(须要联网,由于Maven会自动下载依赖包。)
#cd /root/helloworld/ #mvn package [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building helloworld 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ Downloading: ……………… ##信息太多,此处省略 Downloaded: https://repo.maven.apache.org/maven2/org/apache/maven/surefire/surefire-junit3/2.12.4/surefire-junit3-2.12.4.jar (26 KB at 23.5 KB/sec) ------------------------------------------------------- T E S T S ------------------------------------------------------- Running helloworld.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.001 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ helloworld --- Downloading: ……………… ##此处省略 [INFO] Building jar: /root/helloworld/target/helloworld-1.0-SNAPSHOT.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 01:46 min [INFO] Finished at: 2016-06-22T10:31:06+08:00 [INFO] Final Memory: 16M/40M [INFO] ------------------------------------------------------------------------ 能够看到打包成功了!!
注:下载的依赖包会保存在~/.m2/repository文件夹中,打开这个文件夹,咱们会发现里面的包正是按前面所说的四元组目录结构进行存储的。Maven在依赖一个jar包时会先去本地库查找,若是没找到就会从网上下载。固然,并非全部的包都能从网上下载到,好比咱们本身开发的jar包,这时,咱们就能够用mvn install命令将一个项目安装到本地仓库。
打包成功后咱们会发现项目中多了一个target文件夹,目录结构以下
#tree helloworld/ helloworld/ ├── pom.xml ├── src │ ├── main │ │ └── java │ │ └── helloworld │ │ └── App.java │ └── test │ └── java │ └── helloworld │ └── AppTest.java └── target ├── classes │ └── helloworld │ └── App.class ├── helloworld-1.0-SNAPSHOT.jar ├── maven-archiver │ └── pom.properties ├── maven-status │ └── maven-compiler-plugin │ ├── compile │ │ └── default-compile │ │ ├── createdFiles.lst │ │ └── inputFiles.lst │ └── testCompile │ └── default-testCompile │ ├── createdFiles.lst │ └── inputFiles.lst ├── surefire-reports │ ├── helloworld.AppTest.txt │ └── TEST-helloworld.AppTest.xml └── test-classes └── helloworld └── AppTest.class 20 directories, 13 files
能够看到,在package过程当中,maven完成了编译、测试代码,生成测试报告,生成jar包等一系列工做。
d、手动运行jar包查看结果
#cd /tmp #java -cp /root/helloworld/target/helloworld-1.0-SNAPSHOT.jar helloworld.App Hello World!
e、Maven经常使用命令介绍:
Maven的命令很是多,学习命令首先要了解Maven的生命周期。
Maven首先会验证并处理引用资源,以后进行项目编译,若是没有声明跳过测试,也会编译测试代码并进行测试、以成测试报告。最后,Maven会将编译好的内容进行打包,用于发布。Maven命令与Maven的生命周期有着对应的关系,一个命令也常常会包含多个生命周期,好比mvn package会完成以上全部步骤。
这里列举几个经常使用的命令:
mvn compile 编译项目 mvn test 编译运行单元测试 mvn package 打包(jar or war) mvn install 将项目安装到本地仓库 mvn clean 清空项目 mvn eclipse:eclipse 生成eclipse工程
Maven安装配置部分参考连接:http://www.c4fun.cn/blog/2014/10/10/maven-study/
5、经过Jenkins平台,自动构建jar或者war格式的代码包
一、首先测试拉取代码状况
前面已经在Jenkins配置了一个test_app项目,如今测试构建的状况,选择项目名,以下:
而后在弹出页面的左侧选择“当即构建”,会出现一个进度条,而后点进去,在弹出页面的左侧选择“Console Output”,会看到整个构建过程输出的log,太多了,不能彻底贴出来,不过最后是构建失败了,以下图:
根据错误信息初步判断是一些jar包没有下载成功或者不存在致使的,先放这里,待会再介绍如何解决这个问题。
到Jenkins服务器查看,代码是否已经从git拉取到本机了
#cd /root/.jenkins/workspace ##此时你会看到test_app目录已经存在了 #ll test_app ##代码也已经拉取到本地了 total 16 drwxr-xr-x 2 root root 4096 Jun 21 20:58 build -rw-r--r-- 1 root root 5922 Jun 21 20:58 pom.xml drwxr-xr-x 3 root root 4096 Jun 21 20:58 src
二、解决第1步出现的问题
这里涉及到了maven镜像中央仓库,若是安装好maven以后,没有设置中央仓库(注释掉的),因此没法获取到须要的jar包,就会报错了
设置仓库地址的配置文件在maven的安装目录中,叫settings.xml #cd /usr/local/maven/conf #cat settings.xml | grep url -A 12 -B 12 | server for that repository. |--> <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> ##并且此处的地址也是没法访问的 </mirror> --> </mirrors> <!-- profiles
那须要如何解决这个问题呢,有几种方式:
第一种是使用互联网开放的仓库地址:
a、网上看到的一个开放的仓库地址是国外google的,以下:
<mirrors> <mirror> <id>google-maven-central</id> <name>Google Maven Central</name> <url>https://maven-central.storage.googleapis.com</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors>
因而决定测试一下,将settings.xml文件修改成以下:
#cat settings.xml <?xml version="1.0" encoding="UTF-8"?> <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:\bisoft\tools\maven3\repository</localRepository> --> <pluginGroups> <!-- <pluginGroup>org.mortbay.jetty</pluginGroup> <pluginGroup>org.codehaus.cargo</pluginGroup> --> </pluginGroups> <proxies> </proxies> <servers> <server> <id>releases</id> <username>deployment</username> <password>deployment</password> </server> <server> <id>snapshots</id> <username>deployment</username> <password>deployment</password> </server> </servers> <mirrors> <mirror> <id>google-maven-central</id> <mirrorOf>central</mirrorOf> <url>https://maven-central.storage.googleapis.com</url> ##改成google仓库 </mirror> </mirrors> <profiles> <profile> <id>google-maven-central</id> <repositories> <repository> <id>google-maven-central</id> <name>google-maven-central</name> <url>https://maven-central.storage.googleapis.com</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>google-maven-central</id> <name>google-maven-central</name> <url>https://maven-central.storage.googleapis.com</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>google-maven-central</activeProfile> </activeProfiles> </settings> </settings>
而后测试构建项目,不过结果是失败的,缘由你们估计已经知道了,在国内google是被墙的,因此没法获取一些jar包,错误提示以下:
因此这种方式行不通,就放弃了!
b、国内的一个开源中国的Maven镜像仓库地址,以下:
<mirrors> <mirror> <id>nexus-osc</id> <mirrorOf>*</mirrorOf> <name>Nexus osc</name> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> </mirrors>
通过测试也是不行的,网上说有时还能够,有时候不行,就是不稳定!
此处参考连接:http://www.linuxidc.com/Linux/2016-01/127012.htm
第二种是本身构建中央仓库,本身调用,下一篇文章中再介绍。
初学,不足之处请多多指出,谢谢!