1 package org.scannotation;
3 import javax.servlet.ServletContext;
4 import javax.servlet.ServletContextEvent;
5 import java.net.MalformedURLException;
7 import java.util.ArrayList;
12 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
13 * @version $Revision: 1 $
15 public class WarUrlFinder
17 public static URL[] findWebInfLibClasspaths(ServletContextEvent servletContextEvent)
19 ServletContext servletContext = servletContextEvent.getServletContext();
20 return findWebInfLibClasspaths(servletContext);
23 public static URL[] findWebInfLibClasspaths(ServletContext servletContext)
25 ArrayList<URL> list = new ArrayList<URL>();
26 Set libJars = servletContext.getResourcePaths("/WEB-INF/lib");
27 for (Object jar : libJars)
31 list.add(servletContext.getResource((String) jar));
33 catch (MalformedURLException e)
35 throw new RuntimeException(e);
38 return list.toArray(new URL[list.size()]);
41 public static URL findWebInfClassesPath(ServletContextEvent servletContextEvent)
43 ServletContext servletContext = servletContextEvent.getServletContext();
44 return findWebInfClassesPath(servletContext);
48 * Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
49 * if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
51 * @param servletContext
52 * @return null if cannot determin /WEB-INF/classes
54 public static URL findWebInfClassesPath(ServletContext servletContext)
56 String path = servletContext.getRealPath("/WEB-INF/classes");
57 if (path == null) return null;
58 File fp = new File(path);
59 if (fp.exists() == false) return null;
64 catch (MalformedURLException e)
66 throw new RuntimeException(e);