I was modifying a project in Java with maven and Spring. In some point the need of having the application context XML outside Tomcat came out. In my case it was being loaded using the ContextLoaderListener. I tried other ways of loading it, but the issue is the same: the classpath.
<build> <resources> <resource> <directory>path/to/application/context/</directory> <includes> <include>*</include> </includes> </resource> </resources> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <webXml>path/to/resource/web.xml</webXml> </configuration> </plugin> </plugins> </build>
I wanted to change path/to/application/context.
Tomcat doesn’t give the access to any file outside where it is running, so all the classpath have to behave this way. It is done this way for security reasons. After struggling a hard time, trying different things and almost give up, I decided to read how Tomcat works. I found this page: http://www.mulesoft.com/tomcat-classpath. It have the answer to my question: add the path to the application context XML in the catalina.properties under the shared loader.
Hope this is useful for someone !