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

How to read file in war ?

 
chen young
Ranch Hand
Posts: 197
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I need to read xml file that is stored inside the jsf web application.

I am saving all the xml files in the following path:
c:\Users\me\NetBeansProjects\manager\src\main\resources\com\cron\dis\resources\template\my_file.xml

after building the war I will get something like this:
..\target\manager-1.0-SNAPSHOT\WEB-INF\classes\com\cron\dis\resources\template\my_file.xml

In order to load the file I am using the Class getResource like this:


I try any possible path combination that I can think and still the URI is empty 

I don’t know what am I doing wrong here ??

This is a jsf web application and I am using NetBeans.

Could someone please explain how can I load the file ??

Any help would be most appreciated

Thanks
 
Tim Holloway
Saloon Keeper
Pie
Posts: 17646
39
Android Eclipse IDE Linux
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your IDE should never determine how you code a program. The IDE won't be available on the production server. Or at least I hope not!

The proper way to read a file that's been bundled into a WAR is to treat it as a WAR resource. I just happen to have some code that will make that easier:


Note that I placed this function in a discrete utilities class. That way my main application code is spared the horror of being laced with framework-specific code.

Note that you should never write to a file in a WAR. Resources in a WAR should be treated as read-only. If you need to write or update, use a directory that's external to both the WAR and to the webapp server.
 
chen young
Ranch Hand
Posts: 197
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much

This is very helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic