Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails application root path

Tags:

grails

jetty

Is there a variable where I can find out the root directory of my Grails application?

for example, I have a folder named chart under \%root%\web-app\images\ where I put my charts in. Once I deploy my Grails application on Jetty, I will get FileNotFoundException because the root path becomes /srv/www/vhosts/domain-name/jetty-version/

I would like to know if there is a variable that returns the root path (like /srv/www/vhosts/domain-name/jetty-version/webapps/myapp), and there should be because CSS uses relative path just fine.

like image 226
steve.yu Avatar asked Dec 24 '09 10:12

steve.yu


3 Answers

solved.

request.getSession().getServletContext().getRealPath("/")

this actually gives me the path to where my application puts the images, css, WEB-INF, etc. folders.

like image 121
steve.yu Avatar answered Nov 19 '22 14:11

steve.yu


System.properties['base.dir']
like image 11
Sev Avatar answered Nov 19 '22 15:11

Sev


I know it is an old question, but this could work if you are not in an http request:

ServletContextHolder.servletContext.getRealPath('/')
like image 9
M. Wangel Avatar answered Nov 19 '22 14:11

M. Wangel