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");
34 for (Object jar : libJars)
38 list.add(servletContext.getResource((String) jar));
40 catch (MalformedURLException e)
42 throw new RuntimeException(e);
45 return list.toArray(new URL[list.size()]);
48 public static URL findWebInfClassesPath(ServletContextEvent servletContextEvent)
50 ServletContext servletContext = servletContextEvent.getServletContext();
51 return findWebInfClassesPath(servletContext);
55 * Find the URL pointing to "/WEB-INF/classes" This method may not work in conjunction with IteratorFactory
56 * if your servlet container does not extract the /WEB-INF/classes into a real file-based directory
58 * @param servletContext
59 * @return null if cannot determin /WEB-INF/classes
61 public static URL findWebInfClassesPath(ServletContext servletContext)
63 String path = servletContext.getRealPath("/WEB-INF/classes");
64 if (path == null) return null;
65 File fp = new File(path);
66 if (fp.exists() == false) return null;
71 catch (MalformedURLException e)
73 throw new RuntimeException(e);