0

I need to parse a number of files in my web application.

The files are sitting in a directory (called "edms") at the top level of my .war file. When I try to get a handle on the directory for processing I get errors as the resource returned is of vfszip protocol type.

For example, when I use MyClass.class.getResource("/edms") I get back something like "vfszip:C:/jboss/server/default/deploy/MyWar.war/edms".

If I then use this URL with File objects it fails as it cannot find the underlying directory and the files it contains.

I've looked at using the Spring ResourceUtils class but can't seem to get them to give me what I was which is to be able to :-

  1. Get a handle on the directory (within my .war file)
  2. Loop round each file in the directory - reading and parsing it's contents

Any ideas?

Thanks

Sarah

Sarah Rushworth
  • 813
  • 3
  • 9
  • 16
  • even I have the same problem. trying to read an XML file using getResource("configuration.xml"), but am not able to read this file as it is residing inside EAR. Any solution you got for this friend ?? – Arun Mar 18 '12 at 17:32

2 Answers2

0

As a hack, what happens if you just substring the protocol part of what MyClass.class.getResource("/edms") returns away, and use the rest of it in a new File(...) statement?

DaveH
  • 7,187
  • 5
  • 32
  • 53
  • I did that but then I get a FileNotFound exception :-( I think it's because it is inside a WAR file so without that protocol that file doesn't physically exist on the filesystem in that directory. – Sarah Rushworth Oct 27 '11 at 13:18
  • Only other suggestion I've got is to have a look at http://stackoverflow.com/questions/4899371/why-cant-i-open-a-jboss-vfs-url . Seems like a similar ( but far from identical ) problem. – DaveH Oct 28 '11 at 13:58
0

There are a few possible solution to this:

  • for one thing, upgrade to Spring 3+ should automatically solve this issue (use Spring 3.0.3+ for JBoss AS6 or higher;
  • If you are stuck with Spring 2.5, then you can use Snowdrop (http://www.jboss.org/snowdrop), and more specifically the VfsXmlWebApplicationContext (read this for details.

Hope this helps, Marius

Marius Bogoevici
  • 2,380
  • 1
  • 13
  • 14