File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Refer To dir & files in WAR Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Refer To dir & files in WAR" Watch "Refer To dir & files in WAR" New topic
Author

Refer To dir & files in WAR

Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
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?


A. Valentin
brad balmer
Ranch Hand

Joined: Mar 08, 2004
Posts: 57
Have you tried:

Where the filename (I believe) is based on your context root (WEB-INF/classes)
Ariel Valentin
Ranch Hand

Joined: Jan 30, 2004
Posts: 44
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

Joined: Jun 08, 2002
Posts: 3178
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...


Co-author of SCMAD Exam Guide, Author of JMADPlus
SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2578

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

Joined: Jun 08, 2002
Posts: 3178
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

Joined: Sep 22, 2001
Posts: 2578

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
 
 
subject: Refer To dir & files in WAR
 
Similar Threads
Modify build xml to replace words in an xml or properties file based on a text file
Tomcat weirdness -- incomplete WAR explosion, display of out-of-date (cached?) JSP
using .war file
I want my ant script Implement a function
Default file creation in Eclipse Europa