• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to get absolute path for web application's war file

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How to obtain the absolute path for my web application's war file, using HttpServletRequest
for e.g I need path as D:\apache-tomcat-5.5.28\webapps\war_file_name
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is nothing in the spec that returns the path to the actual war file.

If tomcat is configured to upack the war file on deployment (which is the default), using ServletContext.getRealPath ServletContext.getRealPath will return the location of the your app's directory structure. Read the docs for that method carefully though. Java web applications do not always have to be unpacked directory structures. When they're not, getRealPath will return null. This means that relying on it will make your app less portable and very dependent on the way it will be deployed.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can use the ClassLoader to find the location of a class file as a file, but you need to be sure to load it as a URL and file location since you can't get a java.io.File location for something inside a WAR.
Once you have the URL to the WAR you can extract the first part which will be the file location of the WAR
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nilk, May i know why do you need to get the WAR file path? So that can think of an alternatives...
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic