Alessandro Melandri

WebSphere Commerce Specialist, project manager, wannabe photographer

Get the WEB-INF Folder Path

This is a simple example on how to get the WEB-INF directory path in a J2EE web application.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class MyClassName {

  private static final String WEBINF = "WEB-INF";

  public String getWebInfPath(){

    String filePath = "";

    URL url = MyClassName.class.getResource("MyClassName.class");

    String className = url.getFile();

    filePath = className.substring(0,className.indexOf(WEBINF) + WEBINF.length());

    return filePath;

  }
}