解壓war包和重新壓縮war包

2021-07-25 10:56:21 字數 2203 閱讀 6967

public class warutils  else 

}in.close();

} catch (filenotfoundexception e) catch (archiveexception e) catch (ioexception e) }

/*** 判斷war包是否已經存在,若存在則刪除

* @param filepath

*/public static void delwarfile(string filepath)

} catch (exception e) }

/*** 建立解壓的war包目錄,並返回目錄路徑

* @param warpath war所在路徑

* @param unwarpath war包解壓路徑

* @return

*/public static string mkdirbyfilename(string warpath, string unwarpath)

//判斷檔案後字尾是否war

string filesuffix = filefullname.substring(filefullname.lastindexof(".")+1, filefullname.length());

if(filesuffix.tolowercase().equals("war"))

}return null;

} catch (exception e)

} /**

* @desc 將原始檔/資料夾生成指定格式的壓縮檔案,格式war

* @param resourepath 原始檔/資料夾

* @param targetpath 目的壓縮檔案儲存路徑

* @return void

* @throws exception

*/

public static void compressedfile(string resourcespath,string targetpath) throws exception

string targetname = resourcesfile.getname()+".war"; //目的壓縮檔案名

//壓縮檔案路徑

string targetcomppath = targetpath+"\\"+targetname;

fileoutputstream outputstream = new fileoutputstream(targetcomppath);

zipoutputstream out = new zipoutputstream(new bufferedoutputstream(outputstream));

createcompressedfile(out, resourcesfile, "");

out.close();

}

/**

* @desc 生成壓縮檔案。

* 如果是資料夾,則使用遞迴,進行檔案遍歷、壓縮

* 如果是檔案,直接壓縮

* @param out 輸出流

* @param file 目標檔案

* @return void

* @throws exception

*/

public static void createcompressedfile(zipoutputstream out,file file,string dir) throws exception

} else

//關閉輸入流

fis.close();

} }

//刪除當前目錄以及目錄下的檔案

public static boolean deletedir(file delfile)

}} // 目錄此時為空,可以刪除

return delfile.delete(); }

//檔案重新命名

public static void tofilerename(string filepath,string unwarpath)

}}

涉及到的jar包有ant-1.8.2.jar,ant-launcher-1.8.2.jar,commons-lang-2.6.jar,commons-compress-1.10.jar,commons-io-2.4.jar

jetty和tomcat中,war包解壓縮的差別

jetty中處理war包解壓的 是 org.eclipse.jetty.util.resource.jarresource。使用jarinputstream來讀取war檔案,jarinputstream是首先處理可選的meta inf manifest.mf檔案,也就是說getnextjarentr...

Linux下打包壓縮war,解壓war和jar命令

環境 redhat linux 9 vwware 8.0 ssh 3.2.9 putty 0.62 問題linux下打包壓縮war 解壓war包和jar命令 解決把project a資料夾下的檔案打包成project.war 1,打包 jar xvf project.war project a c ...

linux解壓war包的命令

linux解壓war包的命令 網上很多人說用jar包解壓,但jar命令解壓時不能指定目錄,推薦使用unzip解壓war包。unzip d 指定目錄 root oracle upload unzip oq common.war d common 命令名 unzip 功 能說明 解壓縮zip文 件 語 ...