File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refer To dir & files in WAR

 
Ariel Valentin
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote a webapp and am trying to reference files inside of a war. I use an absolute directory path d:/webapp/dir/filename.xml which, works fine when unpacked, but when I WAR the webapp the classes cannot find the file path specified.
Any suggestions?
 
brad balmer
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried:

Where the filename (I believe) is based on your context root (WEB-INF/classes)
 
Ariel Valentin
Ranch Hand
Posts: 44
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. I will try that, I was just using env-entry's in the webapp referring to the directory but I NOW realize, that of course I cannot reference an absolute file directory because I am using a WAR. I cannot do that with any other archive, what made me think I could in this case?
Thanks again.
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ariel Valentin:
Thanks for the reply. I will try that, I was just using env-entry's in the webapp referring to the directory but I NOW realize, that of course I cannot reference an absolute file directory because I am using a WAR. I cannot do that with any other archive, what made me think I could in this case?
Thanks again.

Did u restart your web container, after you delopyed your WAR in the webapp dir of the web container? If so, you will see the directory is deployed automatically by the container in the webapp folder..... Then you can access to the files in that web app... Hope it helps...
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that not all web containers extract the war file to folders. I guess it is mentioned in the Servlet API docs.
- Manish
 
Ko Ko Naing
Ranch Hand
Posts: 3178
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Manish Hatwalne:
Remember that not all web containers extract the war file to folders. I guess it is mentioned in the Servlet API docs.
- Manish

Really? I didn't know that... It'll be great if you can specify the page in the servlet specification to comfirm that not all web containers extract the war file to folders. Thanks...
 
Manish Hatwalne
Ranch Hand
Posts: 2591
Android Firefox Browser Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's ServletContext of ServletConfig. Check ServletContext.getRealPath()
I believe one of these containers is early versions of Weblogic, not very sure though.... Been some time since I used Weblogic!
Sorry don't have docs here to verify.....
- Manish
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic