Advertisement
santeriv

jboss as 7 classpath URLs of .war

Feb 14th, 2014
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1.     protected URL[] jbossClassLoader(ClassLoader classLoader) {
  2.         List<URL> urls = new ArrayList<URL>();
  3.         Enumeration<URL> resourceURLs;
  4.         try {
  5.             resourceURLs = classLoader.getResources("");
  6.             while(resourceURLs.hasMoreElements())
  7.             {
  8.                 URL resourceURL = resourceURLs.nextElement();
  9.                 String strResourceURL = resourceURL.toString();
  10.                 if(StringUtils.contains(strResourceURL, ".jar"))
  11.                 {
  12.                     URLConnection conn = resourceURL.openConnection();
  13.                     VirtualFile vf = (VirtualFile)conn.getContent();
  14.  
  15.                     URL jarVFSParentURL = VFSUtils.getPhysicalURL(vf.getParent());
  16.                     String jarVFSParentPath = jarVFSParentURL.getFile();
  17.                     List<VirtualFile> childrenJarFiles = vf.getParent().getChildren(new VirtualFileFilter() {
  18.                         @Override
  19.                         public boolean accepts(VirtualFile file) {
  20.                             return file.getName().endsWith(".jar");//filter all other than .jars
  21.                         }
  22.                     });
  23.                     if(childrenJarFiles.size() > 2) {
  24.                         for (VirtualFile virtualJarFile : childrenJarFiles) {
  25.                             //test 1
  26.                             URL jarVFSURL = virtualJarFile.getPhysicalFile().toURI().toURL();
  27.                             String jarVFSPath = jarVFSURL.getFile();
  28.                             urls.add(jarVFSURL);
  29.                             //alternatively
  30.                             String jarFileLocation = jarVFSParentPath + virtualJarFile.getName();
  31.                             File jarFile = new File(jarFileLocation);
  32.                             urls.add(jarFile.toURI().toURL());
  33.                         }
  34.                         break;//while
  35.                     }
  36.                 }
  37.             }
  38.         } catch (IOException e) {
  39.             e.printStackTrace();
  40.         }
  41.         return urls.toArray(new URL[0]);
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement