zoukankan      html  css  js  c++  java
  • eclipse实现JavaWeb应用增量打包

    很多情况下,项目是不允许全量发布的,所以你得把有做修改的文件一个个挑出来,如果有成千上百的文件,你是不是要头大了? 以下方法应该可以让你得到解救!前提是你是用装有svn plugin的eclipse上做开发。

          第一步,用svn生成项目的补丁文件。

          

    选中你需要增量升级的文件,点击完成。

           

       运行如下代码

    Java代码  收藏代码
    1. package verysoft.freepath;  
    2. import java.io.BufferedInputStream;  
    3. import java.io.BufferedOutputStream;  
    4. import java.io.BufferedReader;  
    5. import java.io.File;  
    6. import java.io.FileInputStream;  
    7. import java.io.FileOutputStream;  
    8. import java.io.IOException;  
    9. import java.io.InputStreamReader;  
    10. import java.util.ArrayList;  
    11. import java.util.List;  
    12.   
    13. public class FreePatchUtil {  
    14.   
    15.     public static String patchFile="D:/patch.txt";//补丁文件,由eclipse svn plugin生成  
    16.       
    17.     public static String projectPath="D:/workspace/FordClubJeeCms";//项目文件夹路径  
    18.       
    19.     public static String webContent="WebContent";//web应用文件夹名  
    20.       
    21.     public static String classPath="D:/workspace/FordClubJeeCms/build";//class存放路径  
    22.       
    23.     public static String desPath="C:/Users/xuwen/Desktop/update_pkg";//补丁文件包存放路径  
    24.       
    25.     public static String version="20140711";//补丁版本  
    26.       
    27.       
    28.     /** 
    29.      * @param args 
    30.      * @throws Exception  
    31.      */  
    32.     public static void main(String[] args) throws Exception {  
    33.         copyFiles(getPatchFileList());  
    34.     }  
    35.       
    36.     public static List<String> getPatchFileList() throws Exception{  
    37.         List<String> fileList=new ArrayList<String>();  
    38.         FileInputStream f = new FileInputStream(patchFile);   
    39.         BufferedReader dr=new BufferedReader(new InputStreamReader(f,"utf-8"));  
    40.         String line;  
    41.         while((line=dr.readLine())!=null){   
    42.             if(line.indexOf("Index:")!=-1){  
    43.                 line=line.replaceAll(" ","");  
    44.                 line=line.substring(line.indexOf(":")+1,line.length());  
    45.                 fileList.add(line);  
    46.             }  
    47.         }   
    48.         return fileList;  
    49.     }  
    50.       
    51.     public static void copyFiles(List<String> list){  
    52.           
    53.         for(String fullFileName:list){  
    54.             if(fullFileName.indexOf("src/")!=-1){//对源文件目录下的文件处理  
    55.                 String fileName=fullFileName.replace("src","");  
    56.                 fullFileName=classPath+fileName;  
    57.                 if(fileName.endsWith(".java")){  
    58.                     fileName=fileName.replace(".java",".class");  
    59.                     fullFileName=fullFileName.replace(".java",".class");  
    60.                 }  
    61.                 String tempDesPath=fileName.substring(0,fileName.lastIndexOf("/"));  
    62.                 String desFilePathStr=desPath+"/"+version+"/WEB-INF/classes"+tempDesPath;  
    63.                 String desFileNameStr=desPath+"/"+version+"/WEB-INF/classes"+fileName;  
    64.                 File desFilePath=new File(desFilePathStr);  
    65.                 if(!desFilePath.exists()){  
    66.                     desFilePath.mkdirs();  
    67.                 }  
    68.                 copyFile(fullFileName, desFileNameStr);  
    69.                 System.out.println(fullFileName+"复制完成");  
    70.             }else{//对普通目录的处理  
    71.                 String desFileName=fullFileName.replaceAll(webContent,"");  
    72.                 fullFileName=projectPath+"/"+fullFileName;//将要复制的文件全路径  
    73.                 String fullDesFileNameStr=desPath+"/"+version+desFileName;  
    74.                 String desFilePathStr=fullDesFileNameStr.substring(0,fullDesFileNameStr.lastIndexOf("/"));  
    75.                 File desFilePath=new File(desFilePathStr);  
    76.                 if(!desFilePath.exists()){  
    77.                     desFilePath.mkdirs();  
    78.                 }  
    79.                 copyFile(fullFileName, fullDesFileNameStr);  
    80.                 System.out.println(fullDesFileNameStr+"复制完成");  
    81.             }  
    82.               
    83.         }  
    84.           
    85.     }  
    86.   
    87.     private static void copyFile(String sourceFileNameStr, String desFileNameStr) {  
    88.         File srcFile=new File(sourceFileNameStr);  
    89.         File desFile=new File(desFileNameStr);  
    90.         try {  
    91.             copyFile(srcFile, desFile);  
    92.         } catch (IOException e) {  
    93.             e.printStackTrace();  
    94.         }  
    95.     }  
    96.       
    97.   
    98.       
    99.       
    100.     public static void copyFile(File sourceFile, File targetFile) throws IOException {  
    101.         BufferedInputStream inBuff = null;  
    102.         BufferedOutputStream outBuff = null;  
    103.         try {  
    104.             // 新建文件输入流并对它进行缓冲  
    105.             inBuff = new BufferedInputStream(new FileInputStream(sourceFile));  
    106.   
    107.             // 新建文件输出流并对它进行缓冲  
    108.             outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));  
    109.   
    110.             // 缓冲数组  
    111.             byte[] b = new byte[1024 * 5];  
    112.             int len;  
    113.             while ((len = inBuff.read(b)) != -1) {  
    114.                 outBuff.write(b, 0, len);  
    115.             }  
    116.             // 刷新此缓冲的输出流  
    117.             outBuff.flush();  
    118.         } finally {  
    119.             // 关闭流  
    120.             if (inBuff != null)  
    121.                 inBuff.close();  
    122.             if (outBuff != null)  
    123.                 outBuff.close();  
    124.         }  
    125.     }  
    126.       
    127. }  

    注意,以下部份请按照实际情况填写

    Java代码  收藏代码
    1. public static String patchFile="D:/patch.txt";//补丁文件,由eclipse svn plugin生成  
    2.   
    3. public static String projectPath="D:/workspace/FordClubJeeCms";  
    4.   
    5. public static String webContent="WebContent";//web应用文件夹名  
    6.   
    7. public static String classPath="D:/workspace/FordClubJeeCms/build";//class存放路径  
    8.   
    9. public static String desPath="C:/Users/xuwen/Desktop/update_pkg";//补丁文件包存放路径  
    10.   
    11. public static String version="20140711";//补丁版本  

       好了,运行后得到结果

     如果有多个人都修改了代码,那么每个人在提交代码之前先按第一步生成补丁文件再提交。当所有人都提交代码后,在一台电脑上更新所有代码,再在这台电脑上用以上代码运行所有人生成的补丁文件即可。

  • 相关阅读:
    Go接口特性
    go递归函数
    K8S部署Redis Cluster集群(三主三从模式) 部署笔记
    Jenkins密码忘记重置方法
    inode满了处理
    Linux 系统日常巡检脚本
    垃圾代码评析——关于《C程序设计伴侣》6.2(三)
    CRITICAL THINGKING笔记——ad hominem
    垃圾代码评析——关于《C程序设计伴侣》6.2(二)
    垃圾代码评析——关于《C程序设计伴侣》6.2(一)
  • 原文地址:https://www.cnblogs.com/wanghuaijun/p/5526805.html
Copyright © 2011-2022 走看看