BriteSnow / snow

A Lightweight, Google Guice, Simple, and Powerful Web Application Framework that makes building modern Web Application a breeze! Fully open source, Apache V2 licensed.
http://britesnow.com/snow
29 stars 10 forks source link

app init - servletContext.getRealPath return null #50

Closed jeremychone closed 8 years ago

jeremychone commented 9 years ago

Problem

On Tomcat 8.0.26 + JDK1.8.0.25 and i use BRITESNOW version 2.0.7-SNAPSHOT.

javax.servlet.ServletException: javax.servlet.ServletException: Somehow the servlet container returned null for servletContext.getRealPath(File.separator)
        Cannot initialize with null as realPath. If you use 'mvn jetty:run' make sure you use <groupId>org.eclipse.jetty</groupId> and not the legacy
        <groupId>org.mortbay.jetty</groupId>
        com.britesnow.snow.web.SnowServlet.init(SnowServlet.java:56)

In fact, the problem seems that we are using the File.separator while in fact those servletContext path are virtual path and does not follow OS File.separator.

Solution

servletContext.getRealPath(File.separator) to servletContext.getRealPath("/") should do the trick.

Note: if we still have issues with old version of tomcat or other servlet engines, we might have multiple tries before throwing the exception.