溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

java項目增量打包源碼

發布時間:2020-07-14 04:32:00 來源:網絡 閱讀:2630 作者: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

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女