How to update war content without extracting /unpacking
private static void updateIBPublicationBuilderWar(String installationPath) throws IOException {
String warFilePath = "orignal war file"; // ex test.war
String tempWarFilePath = "temp war file name" ; // temp.war
File warFile = new File(warFilePath);
File tempWarFile = new File(tempWarFilePath);
ZipFile zipFile = new ZipFile(warFile);
FileOutputStream fos = new FileOutputStream(tempWarFile);
ZipOutputStream zipOutputStream = new ZipOutputStream(fos);
for (Enumeration enumeration = zipFile.entries(); enumeration.hasMoreElements();) {
ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
if (!zipEntry.getName().equalsIgnoreCase("WEB-INF/classes/ibserver.properties")) {
zipOutputStream.putNextEntry(zipEntry);
InputStream inputStream = zipFile.getInputStream(zipEntry);
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
zipOutputStream.write(buf, 0, len);
}
inputStream.close();
} else {
zipOutputStream.putNextEntry(new ZipEntry("WEB-INF/classes/ibserver.properties"));
InputStream inputStream = zipFile.getInputStream(zipEntry);
Properties props = new Properties();
props.load(inputStream);
inputStream.close();
props.setProperty("projectspath", installationPath + File.separator + "InBetweenServer" + File.separator + "Projects");
props.setProperty("serverpath", installationPath + File.separator + "InBetweenServer");
props.store(zipOutputStream, null);
inputStream.close();
}
zipOutputStream.closeEntry();
}
zipFile.close();
zipOutputStream.closeEntry();
zipOutputStream.close();
fos.close();
warFile.delete();
File newWarFileName = new File(warFilePath);
tempWarFile.renameTo(newWarFileName);
}
String warFilePath = "orignal war file"; // ex test.war
String tempWarFilePath = "temp war file name" ; // temp.war
File warFile = new File(warFilePath);
File tempWarFile = new File(tempWarFilePath);
ZipFile zipFile = new ZipFile(warFile);
FileOutputStream fos = new FileOutputStream(tempWarFile);
ZipOutputStream zipOutputStream = new ZipOutputStream(fos);
for (Enumeration enumeration = zipFile.entries(); enumeration.hasMoreElements();) {
ZipEntry zipEntry = (ZipEntry) enumeration.nextElement();
if (!zipEntry.getName().equalsIgnoreCase("WEB-INF/classes/ibserver.properties")) {
zipOutputStream.putNextEntry(zipEntry);
InputStream inputStream = zipFile.getInputStream(zipEntry);
byte[] buf = new byte[1024];
int len;
while ((len = inputStream.read(buf)) > 0) {
zipOutputStream.write(buf, 0, len);
}
inputStream.close();
} else {
zipOutputStream.putNextEntry(new ZipEntry("WEB-INF/classes/ibserver.properties"));
InputStream inputStream = zipFile.getInputStream(zipEntry);
Properties props = new Properties();
props.load(inputStream);
inputStream.close();
props.setProperty("projectspath", installationPath + File.separator + "InBetweenServer" + File.separator + "Projects");
props.setProperty("serverpath", installationPath + File.separator + "InBetweenServer");
props.store(zipOutputStream, null);
inputStream.close();
}
zipOutputStream.closeEntry();
}
zipFile.close();
zipOutputStream.closeEntry();
zipOutputStream.close();
fos.close();
warFile.delete();
File newWarFileName = new File(warFilePath);
tempWarFile.renameTo(newWarFileName);
}
Comments
Post a Comment