如何快速搭建一个JAVA持续交付环境

  1. JDK 2.
  2. maven
js 复制代码
https://downloads.apache.org/maven/maven-3/3.9.12/

sudo wget https://archive.apache.org/dist/maven/maven-3/3.9.12/binaries/apache-maven-3.9.12-bin.tar.gz -P /opt
sudo tar -zxvf apache-maven-3.8.8-bin.tar.gz -C /usr/local
sudo mv /usr/local/apache-maven-3.8.8 /usr/local/maven3.8

# 4. 配置环境变量
echo "export MAVEN_HOME=/usr/local/maven3.8" | sudo tee -a /etc/profile
echo "export PATH=\$PATH:\$MAVEN_HOME/bin" | sudo tee -a /etc/profile
source /etc/profile

# 5. 验证安装
mvn -v
  1. 调整设置私有仓库
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>${user.home}/.m2/repository</localRepository>
  
  <!-- 交互模式设置 -->
  <interactiveMode>true</interactiveMode>
  
  <!-- 离线模式设置 -->
  <offline>false</offline>
  
  <!-- 插件组设置 -->
  <pluginGroups></pluginGroups>
  
  <!-- 代理设置(如果使用代理) -->
  <proxies></proxies>
  
  <!-- 镜像配置 -->
  <mirrors>
    <mirror>
      <id>zgf-mirror</id>
      <name>zgf Public Repository Mirror</name>
      <url>http://nexus.zgf.com:8081/nexus/content/groups/public/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>
  
  <!-- Profile 配置 -->
  <profiles>
    <profile>
      <id>zgf-repo</id>
      <!-- 普通依赖仓库 -->
      <repositories>
        <repository>
          <id>zgf-public</id>
          <name>zgf Public Repository</name>
          <url>http://nexus.zgf.com:8081/nexus/content/groups/public/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
          </releases>
          <snapshots>
            <enabled>true</enabled>
            <updatePolicy>always</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
          </snapshots>
        </repository>
      </repositories>
      <!-- 插件仓库 -->
      <pluginRepositories>
        <pluginRepository>
          <id>zgf-public</id>
          <name>zgf Public Plugin Repository</name>
          <url>http://nexus.zgf.com:8081/nexus/content/groups/public/</url>
          <layout>default</layout>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  
  <!-- 激活的 Profile -->
  <activeProfiles>
    <activeProfile>zgf-repo</activeProfile>
  </activeProfiles>
  
  <!-- 服务器认证信息(如果需要) -->
  <servers>
    <!-- 如果需要认证,添加以下配置 -->
    <!--
             <server>
      <id>juzifenqi-public</id>
      <username>your-username</username>
      <password>your-password</password>
    </server>
    -->
  </servers>
  
</settings>
  1. git
shell 复制代码
# 1. 安装Git
sudo yum install -y git

# 2. 验证安装
git --version
  1. 配置公钥到GIT
shell 复制代码
### 1. 生成SSH密钥

ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
### 2. 添加SSH密钥到ssh-agent
eval "$(ssh-agent -s)"

ssh-add ~/.ssh/id_rsa

cat ~/.ssh/id_rsa.pub
  1. 发布脚本
shell 复制代码
#!/bin/bash
cd /data/zgf
echo "开始克隆代码"
if [ ! -d "cmmmmmmm" ]; then
  git clone -b test-uat-251227 git@git.zgf.cn:background/cmmmmmmm.git
  cd cmmmmmmm
  git branch --set-upstream-to=origin/test-uat-251227 test-uat-251227
else
  echo "代码已存在,开始更新"
  cd cmmmmmmm
  git checkout test-uat-251227
  git fetch --all
  git pull origin test-uat-251227 || { echo "拉取失败,尝试重置"; git reset --hard origin/test-uat-251227; }
fi
cd cmmmmmmm-backend
pwd
# 打包
echo "开始打包"
mvn clean package -DskipTests
echo "打包完成"
# 备份旧包
TIMESTAMP=$(date +%Y%m%d%H%M%S)
echo "开始备份旧包到 bak/cmmmmmmm-backend.jar.$TIMESTAMP"
mv /data/App/cmmmmmmm-backend/cmmmmmmm-backend.jar /home/ops/zgfjar/cmmmmmmm-backend.jar.bak.$TIMESTAMP
# 替换新包
echo "替换新包到部署目录"
cp target/cmmmmmmm-backend.jar /data/App/cmmmmmmm-backend/
# 重启服务

cd /data/App/cmmmmmmm-backend/bin
echo "停止服务"
sh stop.sh
echo "启动服务"
sh start.sh
echo "部署完成"
js 复制代码
shell 复制代码
相关推荐
用户2330713074791 分钟前
JUC 并发容器与工具
后端
威武的花瓣22 分钟前
细说ASP.NET的各种异步操作
后端·asp.net·php
漂亮的摩托25 分钟前
如何编写一个SpringBoot项目告警推送的Starter
java·spring boot·后端
任性的芝麻34 分钟前
ASP.NET MVC 中的异步方式
后端·asp.net·mvc
雨师@43 分钟前
go语言项目--实例化(图书管理)--006
开发语言·后端·golang
kuro-shiro1 小时前
SpringBoot 启动流程
java·spring boot·后端
菜鸟是大神1 小时前
【Hermes入门11讲】第七讲:定时自动化——让Hermes成为你的24小时助手
人工智能·github·hermes
newbe365243 小时前
我们如何使用 impeccable 优化前端界面设计与实现稳定性
前端·人工智能·分布式·github·aigc·wpf
一次旅行9 小时前
AI 前沿日报 | 2026年7月3日 星期五
人工智能·github·ai编程
独孤九剑打醒他10 小时前
双层Master-Worker软硬协同调度架构:从根源解决分布式数据一致性难题
后端·嵌入式硬件·硬件架构·硬件工程