You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Majors, Jeremy" <jm...@tribune.com> on 2013/08/01 17:45:48 UTC

GetRealPath Alternative for WAR Deployment

I've seen multiple postings online that state that when you deploy a WAR file rather than using an exploded WAR, then the request.getServletContext().getRealPath() method returns null.  Due to a requirement by my team lead, I cannot deploy the application in any other fashion besides a precompiled WAR file (deploying a folder fixes this issue) and I was using the request.getServletContext().getRealPath()  method so that I could get the version # of the WAR that I have deployed (ex:  myWAR##001.war).  Is there another way to get the version number?  I also looked online to see if there was a way to get the docBase parameter from the context file, but all the postings for that said to use request.getServletContext().getRealPath(), which is returning null.

Any guidance would be greatly appreciated.

Thanks,
Jeremy

Re: GetRealPath Alternative for WAR Deployment

Posted by "Majors, Jeremy" <jm...@tribune.com>.
Thanks Mark.  I ended up doing something similar (added a context
parameter to the context files) which are being generated by the build
process.

Jeremy

On 8/1/13 1:19 PM, "Mark Thomas" <ma...@apache.org> wrote:

>On 01/08/2013 17:45, Majors, Jeremy wrote:
>> I've seen multiple postings online that state that when you deploy a
>> WAR file rather than using an exploded WAR, then the
>> request.getServletContext().getRealPath() method returns null.  Due
>> to a requirement by my team lead, I cannot deploy the application in
>> any other fashion besides a precompiled WAR file (deploying a folder
>> fixes this issue) and I was using the
>> request.getServletContext().getRealPath()  method so that I could get
>> the version # of the WAR that I have deployed (ex:  myWAR##001.war).
>> Is there another way to get the version number?  I also looked online
>> to see if there was a way to get the docBase parameter from the
>> context file, but all the postings for that said to use
>> request.getServletContext().getRealPath(), which is returning null.
>> 
>> Any guidance would be greatly appreciated.
>
>There are ways via Tomcat internals but they tend to get blocked in
>production environments.
>
>The simplest way is to add a version.properties file to WEB-INF/classes
>(kept up to date by your build script) with the information you need and
>access it via the class loader.
>
>Mark
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: GetRealPath Alternative for WAR Deployment

Posted by Mark Thomas <ma...@apache.org>.
On 01/08/2013 17:45, Majors, Jeremy wrote:
> I've seen multiple postings online that state that when you deploy a
> WAR file rather than using an exploded WAR, then the
> request.getServletContext().getRealPath() method returns null.  Due
> to a requirement by my team lead, I cannot deploy the application in
> any other fashion besides a precompiled WAR file (deploying a folder
> fixes this issue) and I was using the
> request.getServletContext().getRealPath()  method so that I could get
> the version # of the WAR that I have deployed (ex:  myWAR##001.war).
> Is there another way to get the version number?  I also looked online
> to see if there was a way to get the docBase parameter from the
> context file, but all the postings for that said to use
> request.getServletContext().getRealPath(), which is returning null.
> 
> Any guidance would be greatly appreciated.

There are ways via Tomcat internals but they tend to get blocked in
production environments.

The simplest way is to add a version.properties file to WEB-INF/classes
(kept up to date by your build script) with the information you need and
access it via the class loader.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org