public class JarModifier
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
META_INF
The directory that stores the manifest and jar signatures
|
static java.lang.String |
SEPERATOR
The directory separator character for archive files as a string
|
| Constructor and Description |
|---|
JarModifier(java.io.File jarFile)
Creates a new JarModifier with the given archive to be modified
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(java.util.jar.JarEntry entry,
byte[] bytes,
boolean overwrite)
Adds (or optionally overwrites) an archive entry with the specified entry
properties.
|
void |
add(java.lang.String entry,
byte[] bytes,
boolean overwrite)
Adds (or optionally overwrites) an archive entry
|
byte[] |
extractEntry(java.lang.String entry) |
static java.util.jar.Manifest |
generateEmptyManifest()
Generates a Jar Manifest based on the given parameters
|
java.util.HashSet<java.lang.String> |
getJarEntrySet() |
java.io.File |
getJarFile() |
java.util.jar.Manifest |
getManifest()
Returns the parsed manifest or null if there is no manifest
|
void |
remove(java.util.jar.JarEntry entry)
Removes the specified entry if one exits (example: a/b/c/test.txt)
|
void |
remove(java.lang.String entry)
Removes the specified entry if one exits (example: a/b/c/test.txt)
|
void |
removeFilesWithName(java.lang.String filename)
Removes any entries with a matching file name (example: test.txt)
|
void |
removeSubdirectory(java.lang.String directory)
Removes any entries with the matching file name prefix
|
void |
save(java.io.File outputArchiveFile)
Writes the modified output archive to a file
|
java.lang.String |
toString()
Prints the contents of the archive file if it were written to disk
|
static void |
unjar(java.io.File inputJar,
java.io.File outputPath)
Extracts a Jar file
|
void |
unsign()
From: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/jarsigner.html
When jarsigner is used to sign a JAR file, the output signed JAR file is exactly the
same as the input JAR file, except that it has two additional files placed in the
META-INF directory: a signature file, with a .SF extension, and a signature block
file, with a .DSA, .RSA, or .EC extension.
|
public static final java.lang.String SEPERATOR
public static final java.lang.String META_INF
public JarModifier(java.io.File jarFile)
throws java.util.jar.JarException,
java.io.IOException
jarFile - The archive to be modified.java.util.jar.JarExceptionjava.io.IOExceptionpublic static void unjar(java.io.File inputJar,
java.io.File outputPath)
throws java.io.IOException
inputJar - outputPath - java.io.IOExceptionpublic java.io.File getJarFile()
public byte[] extractEntry(java.lang.String entry)
throws java.io.IOException
java.io.IOExceptionpublic java.util.jar.Manifest getManifest()
public java.util.HashSet<java.lang.String> getJarEntrySet()
public void unsign()
public static java.util.jar.Manifest generateEmptyManifest()
public void add(java.lang.String entry,
byte[] bytes,
boolean overwrite)
throws java.io.IOException
entry - The entry path (example a/b/c/test.txt)file - The contents of the file to addoverwrite - True if an existing entry should be overwrittenjava.io.IOException - Thrown if overwrite is false and the archive already contains
the specified entrypublic void add(java.util.jar.JarEntry entry,
byte[] bytes,
boolean overwrite)
throws java.io.IOException
entry - JarEntry with the properties to add or overwritefile - The contents of the file to addoverwrite - True if an existing entry should be overwrittenjava.io.IOException - Thrown if overwrite is false and the archive already contains
the specified entrypublic void remove(java.lang.String entry)
entry - public void remove(java.util.jar.JarEntry entry)
entry - public void removeSubdirectory(java.lang.String directory)
directory - public void removeFilesWithName(java.lang.String filename)
filename - The filename to matchpublic void save(java.io.File outputArchiveFile)
throws java.io.IOException
outputArchive - java.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Object