/** {@inheritDoc} */ public void updateManifestEntries(File jar, Map<String, String> manifestentries) throws MojoExecutionException { Manifest manifest = createManifest(jar, manifestentries); File updatedUnprocessedJarFile = new File(jar.getParent(), jar.getName() + "_updateManifestEntriesJar"); ZipFile originalJar = null; JarOutputStream targetJar = null; try { originalJar = new ZipFile(jar); targetJar = new JarOutputStream(new FileOutputStream(updatedUnprocessedJarFile), manifest); // add all other entries from the original jar file Enumeration<? extends ZipEntry> entries = originalJar.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); // skip the original manifest if (JarFile.MANIFEST_NAME.equals(entry.getName())) { continue; } ZipEntry newEntry = new ZipEntry(entry.getName()); targetJar.putNextEntry(newEntry); // write content to stream if it is a file if (!entry.isDirectory()) { InputStream inputStream = null; try { inputStream = originalJar.getInputStream(entry); org.codehaus.plexus.util.IOUtil.copy(inputStream, targetJar); inputStream.close(); } finally { org.apache.maven.shared.utils.io.IOUtil.close(inputStream); } } targetJar.closeEntry(); } targetJar.close(); originalJar.close(); } catch (IOException e) { throw new MojoExecutionException("Error while updating manifest of " + jar.getName(), e); } finally { org.apache.maven.shared.utils.io.IOUtil.close(targetJar); ioUtil.close(originalJar); } // delete incoming jar file ioUtil.deleteFile(jar); // rename patched jar to incoming jar file ioUtil.renameTo(updatedUnprocessedJarFile, jar); }