Is There a Quick Way to Delete a File from a Jar/War Without Having to Extract the Jar and Recreate It

Is there a quick way to delete a file from a Jar / war without having to extract the jar and recreate it?


zip -d file.jar unwanted_file.txt

jar is just a zip file after all. Definitely much faster than uncompressing/recompressing.

How do I update one file in a jar without repackaging the whole jar?

-C is changing the local directory, and is looking for hi.png there. It's not controlling where you're trying to inject it into the JAR file.

I would try making a new directory called images, moving your local hi.png into that, making images a child directory of your current working directory, then just run this:

jar uf myfile.jar images\hi.png

Deleting files using a .jar


// Deletes all files and subdirectories under dir.
// Returns true if all deletions were successful.
// If a deletion fails, the method stops attempting to delete and returns false.
public static boolean deleteDir(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
boolean success = deleteDir(new File(dir, children[i]));
if (!success) {
return false;
}
}
}

// The directory is now empty so delete it
return dir.delete();
}

How do I unsign a jar?

I don't know the answer, but here is what I would do:

  1. Unzip the jar file or files in question (jars are just zips)
  2. Look in the META-INF directory for something that was not MANIFEST-MF.
  3. Delete that stuff.
  4. Open the MANIFEST-MF and remove stuff that looked like it was signature related.
  5. rejar.


Related Topics



Leave a reply



Submit