I am attempting to do some xml marshalling from with spring/tomcat … my app is deployed as normal as a war file. The file is indeed copied to the correct location WEB-INF/classes/myData.xml but I am unsure how to access this from with Java and specifically my spring service layer. As normally I access files from with the app context itself.
I want to do this :
final File xml = new File("WEB-INF/classes/myData.xml");
but in my dev build it goes to F:\eclipse\WEB-INF\classes\myData.xml and not the deployment directory inside tomcat
In Spring, a clean way to do this with Java is using
ClasspathResource:Alternatively, if this is a Spring bean doing the work, then you can inject it from XML, e.g.
… assuming that
myResourceis a javabean property on your Spring bean of typeResource.The
WEB-INF/classesdirectory is automatically on the server’s classpath, you don’t need to (not should you) specify that in the path explicitly.The Spring
Resourceinterface offers various ways to get hold of the data itself (e.g.getInputStream())