java项目增量打包源码
admin
2023-02-19 07:00:03
0次
   为了便于快速的部署增量更新java项目,协助开发写了java项目增量打包工具,每次增量

更新直接覆盖即可,部署人员不用管开发人员提交的文件放在项目的哪个目录,是什么文件,
只要保证部署上去就可以,开发保证提交的文件路径都没有错误即可。
使用方法:
先设置此class文件里项目各类文件存放路径和项目名
提交svn时候,用SVN创建补丁,
选择需要增量更新的文件,
跑一遍此class文件
增量补丁包即在你指定的目录生成了,增量补丁包名字以项目名加时间戳命名,即为补丁号或补丁版本号。

java项目增量打包源码

package com.thinkgem.jeesite.test;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.sun.org.apache.bcel.internal.generic.NEW;
import com.thinkgem.jeesite.common.utils.FileUtils;

public class FreePatchUtil {  

    public static String patchFile="E:/patch0721.txt";//补丁文件,由eclipse svn plugin生成  

    public static String projectPath="D:/mypractises/workspace/Workflow/";//项目文件夹路径  

    public static String webContent="src/main/webapp/WEB-INF";//web应用文件夹名  

    public static String classPath="D:/mypractises/workspace/Workflow/";//class存放路径  

    public static String desPath="C:/Users/cxy/Desktop/update_pkg/";//补丁文件包存放路径  

    public static String projectName = "Workflow";//项目名

    public static SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMMddHHmmss");
    /** 
     * @param args 
     * @throws Exception  
     */  
    public static void main(String[] args) throws Exception { 
        copyFiles(getPatchFileList());  
        FileUtils.zipFiles(desPath+version, "", desPath+projectName+sdFormat.format(new Date())+".zip");
    }  

    public static List getPatchFileList() throws Exception{  
        List fileList=new ArrayList();  
        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);  
            }  
        }   
        return fileList;  
    }  

    public static void copyFiles(List list){  

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

                String tempDesPath=fileName.substring(0,fileName.lastIndexOf("/"));  
                String desFilePathStr=desPath+"/"+version+"/WEB-INF"+tempDesPath.replace("src/main/resources", "/classes/");  
                String desFileNameStr=desPath+"/"+version+"/WEB-INF"+fileName.replace("src/main/resources", "/classes/");  
                File desFilePath=new File(desFilePathStr);  
                if(!desFilePath.exists()){  
                    desFilePath.mkdirs();  
                }  
                copyFile(fullFileName, desFileNameStr);  
                System.out.println(fullFileName+"复制完成");
            }else if(fullFileName.indexOf("/webapp/WEB-INF/views")!=-1){//对web应用文件的处理
                String fileName=fullFileName;  
                fullFileName=classPath+fileName;  

                String tempDesPath=fileName.substring(0,fileName.lastIndexOf("/"));  
                String desFilePathStr=desPath+"/"+version+"/WEB-INF/"+tempDesPath.replace("src/main/webapp/WEB-INF/", "");  
                String desFileNameStr=desPath+"/"+version+"/WEB-INF/"+fileName.replace("src/main/webapp/WEB-INF/", "");  
                File desFilePath=new File(desFilePathStr);  
                if(!desFilePath.exists()){  
                    desFilePath.mkdirs();  
                }  
                copyFile(fullFileName, desFileNameStr);  
                System.out.println(fullFileName+"复制完成");                
            }else{//对静态资源文件的处理
                String fileName=fullFileName;  
                fullFileName=classPath+fileName;  

                String tempDesPath=fileName.substring(0,fileName.lastIndexOf("/"));  
                String desFilePathStr=desPath+"/"+version+tempDesPath.replace("src/main/webapp", "");  
                String desFileNameStr=desPath+"/"+version+fileName.replace("src/main/webapp", "");  
                File desFilePath=new File(desFilePathStr);  
                if(!desFilePath.exists()){  
                    desFilePath.mkdirs();  
                }  
                copyFile(fullFileName, desFileNameStr);  
                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();  
        }  
    }  

}  

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...