I am using Spring -WS to create a web service. In my project, I created a class Helperto read a sample response and request an XML file, which is located in my folder /src/main/resource.
When I do unit testing of my webservice application "locally", I use System.getProperty("user.dir")to get the application context folder. Below is the method I created in the class Helperto help me get the file that interests me in my resources folder.
public static File getFileFromResources(String filename) {
System.out.println("Getting file from resource folder");
File request = null;
String curDir = System.getProperty("user.dir");
String contextpath = "C:\\src\\main\\resources\\";
request = new File(curDir + contextpath + filename);
return request;
}
However, after "publishing" the compiled WAR file to a folder ../webappsin the Apache Tomcat directory, I realize that it System.getProperty("user.dir")no longer returns the path to the application context. Instead, it returns the Apache Tomcat root directory as shown
C:\Program Files\Apache Software Foundation\Tomcat 6.0\src\main\resources\SampleClientFile
- -. - Spring, , :
request.getSession().getServletContext().getContextPath()
- Spring, . Spring -WS, - . webservice.
-
C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\clientWebService\WEB-INF\classes
- ?