Reputation: 10061
Sure this question has been asked some times already. Still, I don't get the right answer until now.
Using Eclipse, I did the following steps:
Dynamic Web Project
It all works and the service more or less starts. Apparently, a WSDL (which I will use later) is generated as well.
In the constructor of my service implementation, I'm desperately trying to read a custom file - which resides in WebContent
I'm not very experienced at creating web services. But I'm using Tomcat 7, Axis 2 and some JPA. In any case, I cannot access the ServletContext
class. I'm not implementing my own servlet either.
I tried all of these:
`new File(".").getAbsolutePath()`
--> returns my own home directory.
@Resource
private WebServiceContext context;
....
ServletContext servletContext =
(ServletContext) context.getMessageContext().get(MessageContext.SERVLET_CONTEXT);
--> context
is always null. I found somewhere, that this is only injected after calling a first service method. Not really my solution.
Don't have the code handy anymore, I used some snippet with NIO. Gotta find it... Didn't work either.
Upvotes: 0
Views: 621
Reputation: 176
If you are trying to read a file in the service, you can place it in the package and access as a resource.
InputStream is = className.class.getResourceAsStream("filename.xml");
Upvotes: 1