On 8/6/2012 12:40 PM, Caldarale, Charles R wrote:
From: Miguel Almeida [mailto:migueldealme...@gmail.com]
Subject: [Tomcat 7] Why can't you use automatic deployment
and exploded WAR when docBase is outside appBase?
The motivation for this is a simple code ServletContext.getRealPath("/")
to create a simple temporary inputstream that works in Tomcat6 but doesn't
in Tomcat7 (because getRealPath("/") will return null).
And, if you check the servlet spec, getRealPath() is *never* guaranteed to
work. Your code should be using either getResourceAsStream() or looking at the
javax.servlet.context.tempdir context attribute to find where it can create
temporary files.
- Chuck
+1
I just spent the better part of a week ferreting out exactly this mess.
The original application would read from and write to files inside the
web application. Even worse, the original application hard-coded the
path in a set of variables set at web application load time.
This meant that every time the server was changed, the application
moved, or the application name changed, the war file had to be unpacked,
these values changed, and then the war file had to be repacked.
Use getResourceAsStream() for things you need to read. Put those items
in WEB-INF/classes or in a jar in WEB-INF/lib. If you need to write
temporary files, use java.io.tmpdir, file.separator, and possibly
createTempFile().
Tomcat (catalina.sh) sets java.io.tmpdir to $CATALINA_BASE/temp for your
convenience by default.
. . . just my (somewhat frustrated) 2 cents.
/mde/
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org