java怎么打增量包_eclipse实现JavaWeb应用增量打包
很多情況下,項目是不允許全量發布的,所以你得把有做修改的文件一個個挑出來,如果有成千上百的文件,你是不是要頭大了? 以下方法應該可以讓你得到解救!前提是你是用裝有svn plugin的eclipse上做開發。
第一步,用svn生成項目的補丁文件。
選中你需要增量升級的文件,點擊完成。
運行如下代碼
package verysoft.freepath;
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.util.ArrayList;
import java.util.List;
public class FreePatchUtil {
public static String patchFile="D:/patch.txt";//補丁文件,由eclipse svn plugin生成
public static String projectPath="D:/workspace/FordClubJeeCms";
public static String webContent="WebContent";//web應用文件夾名
public static String classPath="D:/workspace/FordClubJeeCms/build";//class存放路徑
public static String desPath="C:/Users/xuwen/Desktop/update_pkg";//補丁文件包存放路徑
public static String version="20140711";//補丁版本
/**
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
copyFiles(getPatchFileList());
}
public static List getPatchFileList() throws Exception{
List fileList=new ArrayList();
FileInputStream f = new FileInputStream(patchFile);
BufferedReader dr=new BufferedReader(new InputStreamReader(f));
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 list){
for(String fullFileName:list){
if(fullFileName.indexOf("src/")!=-1){//對源文件目錄下的文件處理
String fileName=fullFileName.replace("src","");
fullFileName=classPath+fileName;
if(fileName.endsWith(".java")){
fileName=fileName.replace(".java",".class");
fullFileName=fullFileName.replace(".java",".class");
}
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{//對普通目錄的處理
String desFileName=fullFileName.replaceAll(webContent,"");
fullFileName=projectPath+"/"+fullFileName;//將要復制的文件全路徑
String fullDesFileNameStr=desPath+"/"+version+desFileName;
String desFilePathStr=fullDesFileNameStr.substring(0,fullDesFileNameStr.lastIndexOf("/"));
File desFilePath=new File(desFilePathStr);
if(!desFilePath.exists()){
desFilePath.mkdirs();
}
copyFile(fullFileName, fullDesFileNameStr);
System.out.println(fullDesFileNameStr+"復制完成");
}
}
}
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();
}
}
}
注意,以下部份請按照實際情況填寫
public static String patchFile="D:/patch.txt";//補丁文件,由eclipse svn plugin生成
public static String projectPath="D:/workspace/FordClubJeeCms";
public static String webContent="WebContent";//web應用文件夾名
public static String classPath="D:/workspace/FordClubJeeCms/build";//class存放路徑
public static String desPath="C:/Users/xuwen/Desktop/update_pkg";//補丁文件包存放路徑
public static String version="20140711";//補丁版本
好了,運行后得到結果
有任何問題請聯系qq 359709421我的網店,有勞各位參觀參觀?外鏈網址已屏蔽
總結
以上是生活随笔為你收集整理的java怎么打增量包_eclipse实现JavaWeb应用增量打包的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据结构之平衡树:2-3查找树的介绍——
- 下一篇: python 16bit转8bit的工具