Linux环境中拉取svn服务器代码并通过maven编译部署发布过程指导
1,客户端需要检出代码
1) 创建一个作为检出代码目录,专门存放检出代码(目录自定义):小编这里存放在 /usr/local/svn-maven 目录下:
mkdir /usr/local/svn-maven
2) 项目代码检出 svn co svn://ip/svnhome,小编这里用的本Linux上的svn的demo
在 /usr/local/svn-maven/目录下检出: svn co svn://ip/demo
2,编辑一键更新代码并打包部署发布shell脚本
1)在用户目录创建一个shell脚本文件 (一般我们连接Linux服务器后所在目录,比较方便).小编这里root用户登录的:
所以在/root/目录下创建shell脚本文件:touch /root/demo.sh
2)编辑文件内容
(1) 首先进入检出项目目录,小编的代码存放目录是 /usr/local/svn-maven/ 项目为demo:
cd /usr/local/svn-maven/demo/ :
(2) 拉取最新代码( 更新代码):svn up
(3) 进入pom.xml目录(只有在当前目录maven才能编译打包): cd demo
(4) 执行编译打包命令,第一次打包可能会很慢,因为需要下载依赖jar包文件。:mvn -U clean install
(5)停掉tomcat: /usr/local/tomcat8.0/bin/shutdown.sh 这里小编的tomcat安装在 /usr/local/ 目录下,根据自己安装目录停掉tomcat,暂停5秒钟。
(6) 删除tomcat工作目录下此项目的文件及war包(小编这里为测试环境,工作目录下有多个项目) :
rm -rf /usr/local/tomcat8.0/webapps/demo.war
rm -rf /usr/local/tomcat8.0/webapps/demo
(7) 将打包好的 demo-0.0.1-SNAPSHOT.war(小编打包好的.war是demo-0.0.1-SNAPSHOT.war)包
拷贝到tomcat工作目录,并重命名为demo.war: cp /usr/local/svn-maven/demo/demo/target/demo-0.0.1-SNAPSHOT.war /usr/local/tomcat8.0/webapps/demo.war
注意: 重命名的war包名必须和第(6)里删除的文件war包名称一致。如果你想让当前项目为tomcat的根目录,只需要将demo.war改为ROOT.war,ROOT为tomcat默认根目录
(8) 启动tomcat:
/usr/local/tomcat8.0/bin/startup.sh
最终demo.sh文件内容如下:
3,测试,日志如下,
[root@Reyco ~]# sh demo.sh
>>>>>>>>>>>>>>>>>>>>>>>进入代码检出目录
>>>>>>>>>>>>>>>>>>>>>>>执行更新,获取最新代码
Updating '.':
D demo/src/main/webapp/js
D demo/src/main/webapp/user
D demo/src/main/webapp/imags
D demo/src/main/webapp/laypage
D demo/src/main/webapp/css
D demo/src/main/webapp/index1.html
D demo/src/main/webapp/index.html
A demo/src/main/webapp/index.html
Updated to revision 18.
>>>>>>>>>>>>>>>>>>>>>>>进入有pom.xml文件目录
>>>>>>>>>>>>>>>>>>>>>>>>编译打包.war文件
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------< com.reyco.core:demo >-------------------------
[INFO] Building demo 0.0.1-SNAPSHOT
[INFO] --------------------------------[ war ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ demo ---
[INFO] Deleting /usr/local/svn-maven/demo/demo/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 10 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ demo ---
[INFO] Compiling 13 source files to /usr/local/svn-maven/demo/demo/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /usr/local/svn-maven/demo/demo/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ demo ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.2:war (default-war) @ demo ---
[INFO] Packaging webapp
[INFO] Assembling webapp [demo] in [/usr/local/svn-maven/demo/demo/target/demo-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp resources [/usr/local/svn-maven/demo/demo/src/main/webapp]
[INFO] Webapp assembled in [168 msecs]
[INFO] Building war: /usr/local/svn-maven/demo/demo/target/demo-0.0.1-SNAPSHOT.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ demo ---
[INFO] Installing /usr/local/svn-maven/demo/demo/target/demo-0.0.1-SNAPSHOT.war to /root/.m2/repository/com/reyco/core/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.war
[INFO] Installing /usr/local/svn-maven/demo/demo/pom.xml to /root/.m2/repository/com/reyco/core/demo/0.0.1-SNAPSHOT/demo-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.160 s
[INFO] Finished at: 2018-11-28T19:40:07+08:00
[INFO] ------------------------------------------------------------------------
>>>>>>>>>>>>>>>>>>>>>>>>stop tomcat?
Using CATALINA_BASE: /usr/local/tomcat8.0
Using CATALINA_HOME: /usr/local/tomcat8.0
Using CATALINA_TMPDIR: /usr/local/tomcat8.0/temp
Using JRE_HOME: /usr/local/jdk1.8.0
Using CLASSPATH: /usr/local/tomcat8.0/bin/bootstrap.jar:/usr/local/tomcat8.0/bin/tomcat-juli.jar
>>>>>>>>>>>>>>>>>>>>>>>>暂停5秒
sleep 1
sleep 2
sleep 3
sleep 4
sleep 5
>>>>>>>>>>>>>>>>>>>>>>>>删除tomcat工作目录下此项目的文件及war包
>>>>>>>>>>>>>>>>>>>>>>>>copy项目到tomcat工作目录,并重命名demo.war
>>>>>>>>>>>>>>>>>>>>>>>>start tomcat
Using CATALINA_BASE: /usr/local/tomcat8.0
Using CATALINA_HOME: /usr/local/tomcat8.0
Using CATALINA_TMPDIR: /usr/local/tomcat8.0/temp
Using JRE_HOME: /usr/local/jdk1.8.0
Using CLASSPATH: /usr/local/tomcat8.0/bin/bootstrap.jar:/usr/local/tomcat8.0/bin/tomcat-juli.jar
Tomcat started.
现在我们就可以访问一下 http://ip/demo
到此整个部署已经完成。