Last active
December 23, 2015 03:19
-
-
Save naoty/6572467 to your computer and use it in GitHub Desktop.
Extract class files which contains Java Class Library and other libraries
This file contains hidden or 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 PackageReflection.java | |
| $ java PackageReflection > packages.txt | |
| $ grep "java.lang.String" packages.txt | |
| java/lang/String$1.class | |
| java/lang/String$CaseInsensitiveComparator.class | |
| java/lang/String.class | |
| java/lang/StringBuffer.class | |
| java/lang/StringBuilder.class | |
| java/lang/StringValue$1.class | |
| java/lang/StringValue$StringCache.class | |
| java/lang/StringValue$StringCacheEntry.class | |
| java/lang/StringValue$StringProfile.class | |
| java/lang/StringValue.class | |
| java/beans/java_lang_String_PersistenceDelegate.class | |
| java/lang/String$1.class | |
| java/lang/StringCoding$1.class | |
| java/lang/StringIndexOutOfBoundsException.class | |
| java/lang/StringValue.class | |
| java/lang/StringCoding$StringEncoder.class | |
| java/lang/StringCoding$StringDecoder.class | |
| java/lang/StringCoding.class | |
| java/lang/StringBuilder.class | |
| java/lang/String$CaseInsensitiveComparator.class | |
| java/lang/StringBuffer.class | |
| java/lang/String.class | |
| $ grep "java.util.ArrayList" packages.txt | |
| java/util/ArrayList.class | |
| $ |
This file contains hidden or 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.util.*; | |
| import java.util.zip.*; | |
| import java.io.*; | |
| public class PackageReflection { | |
| public static void main(String[] args) { | |
| ArrayList<String> paths = getLibraryPaths(); | |
| for (String path : paths) { | |
| if (path.endsWith(".jar") || path.endsWith(".zip")) { | |
| try { | |
| ArrayList<String> classNames = getClassNamesInFile(path); | |
| for (String className : classNames) { | |
| System.out.println(className); | |
| } | |
| } catch (IOException e) { | |
| continue; | |
| } | |
| } | |
| } | |
| } | |
| public static ArrayList<String> getLibraryPaths() { | |
| ArrayList<String> paths = new ArrayList<String>(); | |
| String path = System.getProperty("java.home") + File.separator + ".." + File.separator + "Classes" + File.separator; | |
| File dir = new File(path); | |
| File[] files = dir.listFiles(); | |
| for (File file : files) { | |
| paths.add(file.getAbsolutePath()); | |
| } | |
| return paths; | |
| } | |
| public static ArrayList<String> getClassNamesInFile(String path) throws IOException { | |
| ArrayList<String> classNames = new ArrayList<String>(); | |
| ZipFile file = new ZipFile(path); | |
| Enumeration<? extends ZipEntry> entries = file.entries(); | |
| while (entries.hasMoreElements()) { | |
| ZipEntry entry = entries.nextElement(); | |
| if (entry != null && entry.getName().endsWith(".class")) { | |
| classNames.add(entry.getName()); | |
| } | |
| } | |
| return classNames; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment