示例#1
0
 private static void addJarPath(Set<String> set, File file) {
   String[] names = file.list();
   if (names != null) {
     for (int i = 0; i < names.length; i++) {
       File f = new File(StringUtils.unite(file.getPath(), File.separator, names[i]));
       if (f.isFile() && f.getName().endsWith(".jar")) {
         set.add(f.getPath());
       } else {
         addJarPath(set, f);
       }
     }
   }
 }
示例#2
0
 public static Set<String> getClassOrJarPaths() {
   Set<String> pathSet = new HashSet<>();
   URL url = CentralController.class.getClassLoader().getResource("");
   if (url != null) {
     String path = url.getPath();
     if (path.endsWith("/")) {
       path = path.substring(0, path.lastIndexOf("/"));
     }
     path = path.substring(0, path.lastIndexOf("/") + 1);
     addJarPath(pathSet, new File(path));
   }
   String[] paths = new String[] {"java.class.path", "java.ext.dirs", "sun.boot.class.path"};
   String delim = ":";
   if (System.getProperty("os.name").indexOf("Windows") != -1) {
     delim = ";";
   }
   for (int p = 0; p < paths.length; p++) {
     String[] jarPaths = System.getProperty(paths[p]).split(delim);
     for (int i = 0; i < jarPaths.length; i++) {
       pathSet.add(jarPaths[i]);
     }
   }
   return pathSet;
 }