温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

java项目增量打包源码

发布时间:2020-07-14 04:32:00 来源:网络 阅读:2579 作者:suibiandonggua 栏目:软件技术
   为了便于快速的部署增量更新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<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);  
            }  
        }   
        return fileList;  
    }  

    public static void copyFiles(List<String> 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();  
        }  
    }  

}  
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI