public static File[] getSystemLibs() { File javaHome = new File(System.getProperty("java.home")); File libDir = new File(javaHome, "lib"); File extDir = new File(libDir, "ext"); File osxDir = new File(javaHome.getParentFile(), "Classes"); File[][] libsArray = new File[][] { getLibraryFiles(libDir), getLibraryFiles(osxDir), getLibraryFiles(extDir), }; int nLibs = 0; for (int i = 0; i < libsArray.length; i++) { if (libsArray[i] != null) { nLibs += libsArray[i].length; } } File[] libs = new File[nLibs]; int destPos = 0; for (int i = 0; i < libsArray.length; i++) { if (libsArray[i] != null) { System.arraycopy(libsArray[i], 0, libs, destPos, libsArray[i].length); destPos += libsArray[i].length; } } return libs; }
public static File[] getLibraryFiles(File searchDir) { return searchDir.listFiles( new FilenameFilter() { public boolean accept(File dir, String name) { name = name.toLowerCase(); return name.endsWith(".jar") || name.endsWith(".zip"); } }); }