Accessing web.xml from unit tests? getResourc eAsStream…
Gordon Henriksen <[email protected]>
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
We're using Eclipse and Maven. I've got some unit tests for a web
application (war packaging), and I'd like to pull in web.xml for
servletunit. I was being really deeply and exceedingly lazy and using:
new ServletRunner(new File("./src/webapp/web.xml"), "/context");
This smacks of ‘the wrong way to do it’ to me, but it was sufficient
for the task at hand.
And it worked fine under Eclipse, but then I went to mvn test before
committing; to my disappointment, Maven runs the unit tests relative
to the parent pom, more often than not, so I can't use a relative
path. After some research I tried this instead:
new ServletRunner(Thread.getContextClassLoader
().getResourceAsStream("/WEB-INF/web.xml"), "/context");
That gets me no love, though. Am I using the wrong path? I've tried
several different methods of getting class loaders, and several
different path names, but to no avail. Is anyone else doing this? And
please forgive any naiveté regarding Java resource handling. :)
In the meantime, I'm hardcoding the registerServlet calls, but I
don't like the duplication.
— G