Created
March 6, 2014 22:10
-
-
Save ratnikov/9400830 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javac Test.java && java -classpath . Test | |
enties for test.jar: | |
META-INF/ | |
META-INF/MANIFEST.MF | |
Test.java | |
Done for test.jar | |
process jar tf test.jar: META-INF/ | |
process jar tf test.jar: META-INF/MANIFEST.MF | |
process jar tf test.jar: Test.java | |
process zip -d test.jar Test.java: deleting: Test.java | |
process jar tf test.jar: META-INF/ | |
process jar tf test.jar: META-INF/MANIFEST.MF | |
enties for test.jar: | |
META-INF/ | |
META-INF/MANIFEST.MF | |
Test.java | |
Done for test.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.util.jar.*; | |
import java.util.*; | |
public class Test { | |
public static final void main(String[] args) throws Exception { | |
exec("jar cf test.jar Test.java"); | |
print(new JarFile("test.jar")); | |
exec("jar tf test.jar"); | |
exec("zip -d test.jar Test.java"); | |
exec("jar tf test.jar"); | |
print(new JarFile("test.jar")); | |
} | |
private static void exec(String cmd) throws Exception { | |
Process p = Runtime.getRuntime().exec(cmd); | |
p.waitFor(); | |
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
String line; | |
while ((line = br.readLine()) != null) { | |
System.out.println("process " + cmd + ": " +line); | |
} | |
} | |
private static void print(JarFile jar) { | |
System.out.println("enties for " + jar.getName() + ":"); | |
Enumeration<JarEntry> entries = jar.entries(); | |
while (entries.hasMoreElements()) { | |
System.out.println(entries.nextElement().getName()); | |
} | |
System.out.println("Done for " + jar.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment