Java项目的自动更新并构建脚本

Posted 黄海的编程知识世界

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Java项目的自动更新并构建脚本相关的知识,希望对你有一定的参考价值。

一、安装支撑包,有则改之,无则嘉勉

cd /etc/yum.repos.d/
yum -y install wget
wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
mv CentOS7-Base-163.repo Centos-Base.repo
yum clean all
yum makecache

yum -y update
sed -i ‘s/SELINUX=enforcing/SELINUX=disabled/g‘ /etc/selinux/config
setenforce 0
systemctl stop firewalld
systemctl disable firewalld

yum -y install telnet git net-tools deltarpm epel-release gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel zip unzip ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssh openssl-devel libxslt-devel libevent-devel ntp libtool-ltdl bison libtool vim-enhanced python  lsof iptraf strace lrzsz kernel-devel kernel-headers pam-devel Tcl/Tk cmake ncurses-devel bison setuptool popt-devel net-snmp screen perl-devel pcre-devel  screen tcpdump rsync sysstat man iptables sudo idconfig  system-config-network-tui bind-utils update arpscan tmux elinks numactl iftop bwm-ng  

二、安装jdk8

cd /usr/local/software
wget https://dsideal.obs.cn-north-1.myhuaweicloud.com/HuangHai/jdk/jdk-8u241-linux-x64.rpm
rpm -ivh jdk-8u241-linux-x64.rpm

mv jdk1.8.0_241-amd64 /usr/java/jdk
echo ‘export JAVA_HOME=/usr/java/jdk‘ >> /etc/bashrc
echo ‘export JRE_HOME=$JAVA_HOME/jre‘ >> /etc/bashrc
echo ‘export PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin‘ >> /etc/bashrc
echo ‘export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/jre/lib‘ >> /etc/bashrc
source /etc/bashrc
echo "JDK install success!"

三、安装Maven

mkdir /usr/local/software -p
mkdir /usr/local/maven -p
cd /usr/local/software
wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
tar -zxvf apache-maven-3.6.3-bin.tar.gz
mv apache-maven-3.6.3 /usr/local/maven/apache-maven-3.6.3

echo ‘MAVEN_HOME=/usr/local/maven/apache-maven-3.6.3‘ >>  /etc/profile
echo ‘export PATH=${MAVEN_HOME}/bin:${PATH}‘  >>  /etc/profile
source /etc/profile
mvn -v

四、开始配置Git并克隆项目

mkdir -p /usr/local/software/ 
cd /usr/local/software/ 
ssh-keygen -t rsa -C "10402852@qq.com"
Generating public/private rsa key pair…
三次回车即可生成 ssh key
查看你的 public key,并把他添加到码云(Gitee.com) SSH key添加地址(https://gitee.com/profile/sshkeys)

cat ~/.ssh/id_rsa.pub

添加后,在终端(Terminal)中输入,测试远程登录是否成功

ssh -T git@gitee.com

若返回

Welcome to Gitee.com, yourname!

则证明添加成功。

git clone git@gitee.com:wanmakeji/Athena.git

五、更新和拉取

cd Athena/
git fetch -v --progress "origin"
git pull --progress -v --no-rebase "origin"

六、编译项目

cd /usr/local/software/Athena/baseServiceJava
mvn clean compile

七、拷贝到目录

mkdir -p /usr/local/tomcat8/webapps/baseService/WEB-INF/classes
mkdir -p /usr/local/tomcat8/webapps/baseService
mkdir -p  /usr/local/tomcat8/webapps/baseService/WEB-INF/lib
cp -r /usr/local/software/Athena/baseServiceJava/target/classes/* /usr/local/tomcat8/webapps/baseService/WEB-INF/classes
cp -r /usr/local/software/Athena/baseServiceJava/WebRoot/*  /usr/local/tomcat8/webapps/baseService
cp -r /usr/local/software/Athena/baseServiceJava/lib/* /usr/local/tomcat8/webapps/baseService/WEB-INF/lib

八、替换ip之类的操作

sed -i ‘s/192.168.2.199/10.100.100.63/‘ /usr/local/tomcat8/webapps/baseService/WEB-INF/classes/application.properties

九、重新启动

echo ‘正在重新启动程序...‘
cd /usr/local/tomcat8/webapps/baseService/WEB-INF/classes &&  ./stop.sh && ./start.sh
echo ‘程序启动成功完成!‘

以上是关于Java项目的自动更新并构建脚本的主要内容,如果未能解决你的问题,请参考以下文章

使用Jekins自动构建项目(GitLab+Java Maven)

CI开发的最佳实践是什么?

java框架Maven的特点

宝塔 自动更新代码代码脚本

怎么把java自动化代码提交到jenkins

Visual Studio下运行PowerShell脚本自动更新项目里AssemblyInfo.cs文件的版本(自增小版本号)并发布到Nuget服务器上