How to get the context name and absolute application path

On March 22, 2011, in JSF, Jsp, by lucasterdev
public void getPaths() {

		FacesContext fcontext = FacesContext.getCurrentInstance();
		String contextName = fcontext.getExternalContext().getContextName();

		ServletContext scontext = (ServletContext) fcontext
				.getExternalContext().getContext();
		String realPath = scontext.getRealPath("/");

		System.out.println("RealPath: " + realPath);
		System.out.println("ContextName: " + contextName);
	}

The output will be the following:


[STDOUT] RealPath: /usr/local/jboss/jboss-6.0.0.Final/server/default/deploy/MYAPPLICATION.war/
[STDOUT] ContextName: MYAPPLICATION

 

Leave a Reply