很多情況下,專案是不允許全量釋出的,所以你得把有做修改的檔案一個個挑出來,如果有成千上百的檔案,你是不是要頭大了? 以下方法應該可以讓你得到解救!前提是你是用裝有svn plugin的eclipse上做開發。

第一步,用svn生成專案的補丁檔案。

選中你需要增量升級的檔案,點選完成。

執行如下程式碼

  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. public class FreePatchUtil {
  13. public static String patchFile="D:/patch.txt";//補丁檔案,由eclipse svn plugin生成
  14. public static String projectPath="D:/workspace/FordClubJeeCms";//專案資料夾路徑
  15. public static String webContent="WebContent";//web應用資料夾名
  16. public static String classPath="D:/workspace/FordClubJeeCms/build";//class存放路徑
  17. public static String desPath="C:/Users/xuwen/Desktop/update_pkg";//補丁檔案包存放路徑
  18. public static String version="20140711";//補丁版本
  19. /**
  20. * @param args
  21. * @throws Exception
  22. */
  23. public static void main(String[] args) throws Exception {
  24. copyFiles(getPatchFileList());
  25. }
  26. public static List<String> getPatchFileList() throws Exception{
  27. List<String> fileList=new ArrayList<String>();
  28. FileInputStream f = new FileInputStream(patchFile);
  29. BufferedReader dr=new BufferedReader(new InputStreamReader(f,"utf-8"));
  30. String line;
  31. while((line=dr.readLine())!=null){
  32. if(line.indexOf("Index:")!=-1){
  33. line=line.replaceAll(" ","");
  34. line=line.substring(line.indexOf(":")+1,line.length());
  35. fileList.add(line);
  36. }
  37. }
  38. return fileList;
  39. }
  40. public static void copyFiles(List<String> list){
  41. for(String fullFileName:list){
  42. if(fullFileName.indexOf("src/")!=-1){//對原始檔目錄下的檔案處理
  43. String fileName=fullFileName.replace("src","");
  44. fullFileName=classPath+fileName;
  45. if(fileName.endsWith(".java")){
  46. fileName=fileName.replace(".java",".class");
  47. fullFileName=fullFileName.replace(".java",".class");
  48. }
  49. String tempDesPath=fileName.substring(0,fileName.lastIndexOf("/"));
  50. String desFilePathStr=desPath+"/"+version+"/WEB-INF/classes"+tempDesPath;
  51. String desFileNameStr=desPath+"/"+version+"/WEB-INF/classes"+fileName;
  52. File desFilePath=new File(desFilePathStr);
  53. if(!desFilePath.exists()){
  54. desFilePath.mkdirs();
  55. }
  56. copyFile(fullFileName, desFileNameStr);
  57. System.out.println(fullFileName+"複製完成");
  58. }else{//對普通目錄的處理
  59. String desFileName=fullFileName.replaceAll(webContent,"");
  60. fullFileName=projectPath+"/"+fullFileName;//將要複製的檔案全路徑
  61. String fullDesFileNameStr=desPath+"/"+version+desFileName;
  62. String desFilePathStr=fullDesFileNameStr.substring(0,fullDesFileNameStr.lastIndexOf("/"));
  63. File desFilePath=new File(desFilePathStr);
  64. if(!desFilePath.exists()){
  65. desFilePath.mkdirs();
  66. }
  67. copyFile(fullFileName, fullDesFileNameStr);
  68. System.out.println(fullDesFileNameStr+"複製完成");
  69. }
  70. }
  71. }
  72. private static void copyFile(String sourceFileNameStr, String desFileNameStr) {
  73. File srcFile=new File(sourceFileNameStr);
  74. File desFile=new File(desFileNameStr);
  75. try {
  76. copyFile(srcFile, desFile);
  77. } catch (IOException e) {
  78. e.printStackTrace();
  79. }
  80. }
  81. public static void copyFile(File sourceFile, File targetFile) throws IOException {
  82. BufferedInputStream inBuff = null;
  83. BufferedOutputStream outBuff = null;
  84. try {
  85. // 新建檔案輸入流並對它進行緩衝
  86. inBuff = new BufferedInputStream(new FileInputStream(sourceFile));
  87. // 新建檔案輸出流並對它進行緩衝
  88. outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));
  89. // 緩衝陣列
  90. byte[] b = new byte[1024 * 5];
  91. int len;
  92. while ((len = inBuff.read(b)) != -1) {
  93. outBuff.write(b, 0, len);
  94. }
  95. // 重新整理此緩衝的輸出流
  96. outBuff.flush();
  97. } finally {
  98. // 關閉流
  99. if (inBuff != null)
  100. inBuff.close();
  101. if (outBuff != null)
  102. outBuff.close();
  103. }
  104. }
  105. }

注意,以下部份請按照實際情況填寫

  1. public static String patchFile="D:/patch.txt";//補丁檔案,由eclipse svn plugin生成
  2. public static String projectPath="D:/workspace/FordClubJeeCms";
  3. public static String webContent="WebContent";//web應用資料夾名
  4. public static String classPath="D:/workspace/FordClubJeeCms/build";//class存放路徑
  5. public static String desPath="C:/Users/xuwen/Desktop/update_pkg";//補丁檔案包存放路徑
  6. public static String version="20140711";//補丁版本

好了,執行後得到結果

如果有多個人都修改了程式碼,那麼每個人在提交程式碼之前先按第一步生成補丁檔案再提交。當所有人都提交程式碼後,在一臺電腦上更新所有程式碼,再在這臺電腦上用以上程式碼執行所有人生成的補丁檔案即可。