idea svn 生成项目升级包的工具

3 篇文章 1 订阅

先上代码

package com.incon.publicTool; /**
 * @描述: TODO方法说明
 * @创建: xiao
 * @日期: 创建于 9:28 2020/9/1 0001
 */


import com.fh.util.DateUtil;
import com.sun.istack.internal.NotNull;

import java.io.*;
import java.util.ArrayList;
import java.util.List;


public class CreatePatchIDEA {


    //补丁文件,操作步骤:eclipse选中项目右击->team->创建补丁包->保存到文件系统->选择文件路径是D:\\根目录,然后生成。
    //一
    public static String patchFile = "E:\\qwe.txt";

    //项目文件夹路径 (eclipse中工作空间,当前项目的路径,到项目名)
    //二
    public static String projectPath = "E:\\IdeaProNew\\pjxt_by\\classes\\artifacts\\pjxt_by";

    //web应用文件夹名  (没啥好说的,只要存放jsp的上级文件夹叫这个名字就可以)
    //三
//    public static String WebRoot = "WebRoot";
    public static String WebRoot = "";

    //class存放路径  (项目的classes文件夹的具体路径)
    //四
    public static String classPath = "E:\\IdeaProNew\\pjxt_by\\classes\\artifacts\\pjxt_by\\WEB-INF\\classes";

    //补丁文件包存放路径 (即导出后的文件路径和文件夹名)
    //五
    public static String desPath = "E:\\更新包名称" ;

    //补丁版本  (里面就是补丁文件包)
    //六
    public static String version = "pjxt_by";


    /**
     * @param args
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        copyFiles(getPatchFileList());
    }

    /****
     * 读取补丁配置文件解析出修改的文件并返回到list集合
     * @return
     * @throws Exception
     */
    public static List<String> getPatchFileList() throws Exception {
        List<String> fileList = new ArrayList<String>();
        FileInputStream f = new FileInputStream(patchFile);
        BufferedReader dr = new BufferedReader(new InputStreamReader(f, "utf-8"));
        String line;
        while ((line = dr.readLine()) != null) {
            if (line.indexOf("Index:") != -1) {
                line = line.replaceAll(" ", "");
                line = line.substring(line.indexOf(":") + 1, line.length());
                fileList.add(line);
            }
        }
        dr.close();
        return fileList;
    }

    /***
     *
     * @param list 修改的文件
     */
    public static void copyFiles(@NotNull List<String> list) {

        for (String fullFileName : list) {
            if (fullFileName.indexOf("src/") != -1) {//对源文件目录下的文件处理
                String fileName = fullFileName.replace("src", "");
                fullFileName = classPath + fileName;
                if (fileName.endsWith(".java")) {
                    fileName = fileName.replace(".java", ".class");
                    fullFileName = fullFileName.replace(".java", ".class");
                }
                String tempDesPath = fileName.substring(0, fileName.lastIndexOf("/"));
                String desFilePathStr = desPath + "/" + version + "/WEB-INF/classes" + tempDesPath;
                String desFileNameStr = desPath + "/" + version + "/WEB-INF/classes" + fileName;
                File desFilePath = new File(desFilePathStr);
                if (!desFilePath.exists()) {
                    desFilePath.mkdirs();
                }
                copyFile(fullFileName, desFileNameStr);
                System.out.println(fullFileName + "复制完成");
            } else {//对普通目录的处理
                String desFileName = fullFileName.replaceAll(WebRoot, "");
                fullFileName = projectPath + "/" + fullFileName;//将要复制的文件全路径
                String fullDesFileNameStr = desPath + "/" + version + desFileName;
                String desFilePathStr = fullDesFileNameStr.substring(0, fullDesFileNameStr.lastIndexOf("/"));
                File desFilePath = new File(desFilePathStr);
                if (!desFilePath.exists()) {
                    desFilePath.mkdirs();
                }
                copyFile(fullFileName, fullDesFileNameStr);
                System.out.println(fullFileName + "复制完成");

            }

        }

    }


    private static void copyFile(String sourceFileNameStr, String desFileNameStr) {
        File srcFile = new File(sourceFileNameStr);
        File desFile = new File(desFileNameStr);
        try {
            copyFile(srcFile, desFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void copyFile(File sourceFile, File targetFile) throws IOException {
        BufferedInputStream inBuff = null;
        BufferedOutputStream outBuff = null;
        try {
            // 新建文件输入流并对它进行缓冲
            inBuff = new BufferedInputStream(new FileInputStream(sourceFile));

            // 新建文件输出流并对它进行缓冲
            outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));

            // 缓冲数组
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1) {
                outBuff.write(b, 0, len);
            }
            // 刷新此缓冲的输出流
            outBuff.flush();
        } finally {
            // 关闭流
            if (inBuff != null)
                inBuff.close();
            if (outBuff != null)
                outBuff.close();
        }
    }
}


首先介绍一下各参数都是干什么用的
代码除了路径需要自己修改外,其它的什么都不需要动
一、生成补丁包用到的路径,下面有介绍哪里会用到
二、项目编译后的路径
三、不用动
四、编译后的Java文件路径
五、生成更新包的路径以及名称
六、项目的名称

当你代码改完后,先别急的提交代码。

第一步
在这里插入图片描述
第二步 (选中你要打包的文件,这里最好不要选择配置文件,然后选中Create Patch…)
在这里插入图片描述
第三步
在这里插入图片描述
第四步 (点击上一步的ok后在E盘就会生成相应的文件)
在这里插入图片描述
第五步(打开txt文件,将 “WebRoot/WEB-INF”全部替换为 “/WEB-INF”,这里是针对web项目,因为普通的web项目编译后的java文件以及jsp、html文件再web-inf下,没有webroot这一层文件夹,所以把webroot去掉只保留web-inf。如果是maven项目的话就看具体位置更改具体的值了)
在这里插入图片描述

第六步 (打开代码,运行main方法)
在这里插入图片描述
第七步 (然后会在你写的 desPath 路径下生成你想要的文件)

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值