Get application full path I have a JSF project composed by some Maven Modules.

I have one module that needs to read and write some files on server. To do this I need to know the "real" full path of the application/server.

The way it is coded, only the View layer can access this information by this method:

public final static String getRealPath(String relativePath) {
    FacesContext fc = FacesContext.getCurrentInstance();
    ServletContext context = (ServletContext)fc.getExternalContext().getContext();

    return context.getRealPath(relativePath);
}


Can my module (not in View layer) call some Faces methods like FacesContext.getCurrentInstance()? Am I breaking some rule, layer or pattern? Or should I pass this path through all layers as a method parameter?
I guess you'd be better off using Class.getRessource() to access your files. I assume they are packaged with your application.

This method would not be restricted to the view layer (where it actually not belongs). And you won't be concerned with servlet container details.