Search code examples
javaspringmavenmaven-resources-plugin

Spring application with external context and resources via maven


Is it possible to build a spring application jar file /w all jar dependencies packaged inside the jar as usual, but resources folder + spring app-context.xml defined outside the jar? If so can anyone point me to an example?

I want to build using maven, if possible, but maven squishes resources to the root of jar and i want those available/captured externally, so I guess there are actually 2 questions here.

  1. How do you make spring consume context/properties from external files. (ex. external "classpath*:/META-INF/spring/applicationContext.xml")
  2. How do you make maven package the jar file, NOT squishing resources to main jar. Though I guess this could be configured via a maven plug-in... I guess the first question is more important, I just figured there was some sort of a template solution for this, but have not been able to find an example.

Solution

  • I was eventually able to get this working using maven-shade-plugin to edit the manifest for uber jar. Once you get the xml incantations just right for the shade plugin, you have to set up rules for spring dependencies that have same-name handlers, which collide each other in classloader. Also you need to modify manifest classpath entries to include your folder names. If done correctly this will give you an "uber" jar + resources it uses sitting neatly in folders adjacent to it. Everything else is standard maven + spring stuff.