-
1. Re: getting file path to webroot?
michaelcourcy Aug 18, 2008 12:00 PM (in response to deanhiller2000)Why not trying to load the resource from the point of view of the class :
this.getClass().getResourceAsStream(<the resources you seek>)
This is likely to be more portable.
Hope this help.
-
2. Re: getting file path to webroot?
mail.micke Aug 18, 2008 1:46 PM (in response to deanhiller2000)If you can get a hold of the ServletContext you can get it by calling:
servletCtx.getRealPath("some/dir/")
-
3. Re: getting file path to webroot?
deanhiller2000 Aug 19, 2008 12:16 AM (in response to deanhiller2000)1. to the first question...
The phone api I am using takes a base file path and not a url :( While in the future, I would like to change that, right now, I need to use KISS and make money before we go out of business :)2. servletCtx
Actually, I knew this already, and I thought one could get this from facesContext but it seems facesContext is not injected if there is no session maybe? I keep getting null for my facescontext and I am taking a wild wild guess that it is because I use the @Startup so the bean starts up to early??? anyone know? I would really like to get that servletCtx path. -
4. Re: getting file path to webroot?
mail.micke Aug 19, 2008 9:26 AM (in response to deanhiller2000)Hi
Does
FacesContext facesContext = FacesContext.getCurrentInstance();
work?
If so you can do this:
ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext(); ServletContext serCtx = (ServletContext) extCtx.getContext();
-
5. Re: getting file path to webroot?
deanhiller2000 Aug 22, 2008 3:51 AM (in response to deanhiller2000)That didn't work. getCurrentInstance() returned null!!! Is this a bug in seam.
NullPointerException occurred on the second line here.....
FacesContext ctx = FacesContext.getCurrentInstance(); ExternalContext extCtx = ctx.getExternalContext(); ServletContext serCtx = (ServletContext) extCtx.getContext();
-
6. Re: getting file path to webroot?
ronaldocwb Sep 23, 2010 5:30 PM (in response to deanhiller2000)Did you got a solution? To get context path inside a @StartUp - @Create method?
-
7. Re: getting file path to webroot?
deanhiller2000 Sep 24, 2010 1:43 PM (in response to deanhiller2000)no, I think I just waited for the very first web request which gave me all the info I needed in it which kinda of was a hack solution.