Skip to main content

Problem with opening files in JAX-WS with tomcat

No replies
robertwerutsky
Offline
Joined: 2010-02-11
Points: 0

Hi all ...

I have a JAX-WS webservice deployed on tomcat
At the webservice startup I need to load a configuration file based on it's relative path (the file is inside the WEB-INF/config)
my code is like that:

@webservice
public class MyWebservice {

public MyWebservice() {
File file = new File("./config/myConfiguration.xml")
System.out.println(file.getCanonicalPath());
}

@webmethod
public void webserviceMethod() {

}
}

but that doesn't work ..... the result of the printf is:
/home/myusername/config/nmmConfiguration.xml

I need something to the get the path to my tomcat WEB-INF
please, what can I do ?

I know I could do this:

@Resource private WebServiceContext wsc;

MessageContext ctxt = wsc.getMessageContext();
ServletContext req = (ServletContext) ctxt.get(ctxt.SERVLET_CONTEXT);
String contextPath = req.getRealPath("WEB-INF");

but this way I need to wait for a request to load the file ... I want to load it at the webservice startup

thanks