Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

linux

jar

People also ask

How do I delete a JAR file?

From the left navigation pane, select JARs from under Resource Browser. The Summary of JARs page is displayed. In the Options field of the JAR you want to delete, click the Delete icon.

Do JAR files need to be extracted?

The JVM is capable of loading classes or files from a jar file without extracting the jar to temp files. This functionality is also available to you in the standard library, see the JarFile for more information. So no, the JVM does not extract a jar to temp files, classes (and resources) are simply loaded on demand.

How do I remove a folder from a JAR file?

Here's the process: Scan forward in the file until you find the first file you want to delete. Scan forward in the file until you find the first file you don't want to delete or you hit the central directory. Scan forward in the file until you find the first file you want to delete or you hit the central directory.


zip -d file.jar unwanted_file.txt

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


In Java you can copy all the entries of a jar except the one you want to delete. i.e. you have to make a copy but don't need to create the individual files.

You can do this by

  • creating a new jar.
  • iterating though the Jar you have
  • copy the entry from one jar to the other, skipping any files you want.
  • close and replace the orginal jar if you want.