Created
January 6, 2010 18:25
-
-
Save mcrisc/270498 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Returns the parent directory of a class being run by a web | |
* container, such as Tomcat. Useful for generating a | |
* value for iReport's SUBREPORT_DIR parameter. | |
* | |
* If using Struts 1.x, call this method this way: | |
<code> | |
getRealPath(getServlet().getServletContext(), YourClassName.class); | |
</code> | |
*/ | |
private String getRealPath(ServletContext context, Class clazz) { | |
StringBuilder path = new StringBuilder(context.getRealPath("WEB-INF")); | |
path.append(File.separator).append("classes").append(File.separator); | |
final Package clazzPackage = clazz != null ? clazz.getPackage() : null; | |
if (clazzPackage != null) { | |
for (String component : clazzPackage.getName().split("\\.")) { | |
path.append(component).append(File.separator); | |
} | |
} | |
return path.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment