当前位置: 首页 > news >正文

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";//补丁版本  

 

   好了,运行后得到结果

 

 

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

相关文章:

  • AngularJS之Filter(二)
  • nginx 负载服务器优化
  • 【SSH网上商城项目实战14】商城首页UI的设计
  • eclipse+python+selenium+mysqldb环境搭建
  • 取模和与运算的优化
  • STORM_0007_Multi-Lang protocol of Storm/多语言协议的翻译
  • Jquery 中map()函数的用法
  • 大公司都有哪些开源项目~~~简化版
  • Java 网络IO编程总结(BIO、NIO、AIO均含完整实例代码)
  • Arm开发板+Qt学习之路-multiple definition of
  • 清除windows系统垃圾文件简易脚本(bat)
  • 1225 八数码难题
  • ES6初探,什么是ES6
  • who命令
  • Android 采用Layout Inflater创建一个View对象
  • AngularJS指令开发(1)——参数详解
  • angular学习第一篇-----环境搭建
  • Electron入门介绍
  • ES6 ...操作符
  • Java 23种设计模式 之单例模式 7种实现方式
  • JavaScript 无符号位移运算符 三个大于号 的使用方法
  • Python 反序列化安全问题(二)
  • 持续集成与持续部署宝典Part 2:创建持续集成流水线
  • 解决jsp引用其他项目时出现的 cannot be resolved to a type错误
  • 实习面试笔记
  • 数据科学 第 3 章 11 字符串处理
  • 说说动画卡顿的解决方案
  • 学习JavaScript数据结构与算法 — 树
  • 用Node EJS写一个爬虫脚本每天定时给心爱的她发一封暖心邮件
  • NLPIR智能语义技术让大数据挖掘更简单
  • python最赚钱的4个方向,你最心动的是哪个?
  • 好程序员大数据教程Hadoop全分布安装(非HA)
  • #mysql 8.0 踩坑日记
  • (02)Hive SQL编译成MapReduce任务的过程
  • (JSP)EL——优化登录界面,获取对象,获取数据
  • (windows2012共享文件夹和防火墙设置
  • (二) Windows 下 Sublime Text 3 安装离线插件 Anaconda
  • (二)【Jmeter】专栏实战项目靶场drupal部署
  • (个人笔记质量不佳)SQL 左连接、右连接、内连接的区别
  • (简单有案例)前端实现主题切换、动态换肤的两种简单方式
  • (五)大数据实战——使用模板虚拟机实现hadoop集群虚拟机克隆及网络相关配置
  • (自用)learnOpenGL学习总结-高级OpenGL-抗锯齿
  • ****Linux下Mysql的安装和配置
  • .describe() python_Python-Win32com-Excel
  • .Net - 类的介绍
  • .Net Attribute详解(上)-Attribute本质以及一个简单示例
  • .net core 调用c dll_用C++生成一个简单的DLL文件VS2008
  • .NetCore Flurl.Http 升级到4.0后 https 无法建立SSL连接
  • .NET上SQLite的连接
  • .sdf和.msp文件读取
  • @Autowired 与@Resource的区别
  • [.net 面向对象程序设计进阶] (19) 异步(Asynchronous) 使用异步创建快速响应和可伸缩性的应用程序...
  • [].slice.call()将类数组转化为真正的数组
  • [2016.7 day.5] T2
  • [android] 看博客学习hashCode()和equals()