Here at Mystic, we do a lot of different types of development. It’s not all web development. I found myself writing a simple document parser that takes files uploaded by automated process, processes them by adding to a database, and finishes. One of the components we used to tie everything together, the Spring Framework, it’s great for that.
Since this would be a command line app running via cron most likely, we pulled Maven and the assembly plugin from our bag-of-tricks. Simply adding something like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.your.main.class.file</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
All was right with the world, until we ran it from the dependency included jar on the server, and BAM!
Exception in thread “main” org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace http://www.springframework.org/schema/context
Ouch, how frustrating, this worked in the IDE “Works on my machine â„¢”. After a bit of googling I realized, we were using separate dependencies for the Spring jars that we needed, and the contents of META-INF/ were getting overwritten (only a single JAR remember?). So the solution was to swap out all the separate Spring dependencies in Maven, and use the all-in-one like so:
1
2
3
4
5
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>${spring.version}</version>
</dependency>