Arka Ghosh Arka Ghosh - 5 months ago 18
Java Question

'spring.schemas' is gettting overwritten while packaging

I've an application where I'm using both the

spring-beans
and
spring-context
jars. When I'm trying to package my application using maven to generate a single jar for my application with dependencies, the
spring.schemas
file of the
spring-context
jar is overwriting that of the
spring-beans
jar. As a result, another application which is using my packaged jar file, can't identify the schema location references of the
spring-beans
.

What's the workaround in such situation?

Answer

After researching quite a bit, I have found the Apache Shade Plugin which is capable of appending the resources as below:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <id>assembly</id>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <transformers>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.handlers</resource>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.schemas</resource>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>META-INF/spring.tooling</resource>
                    </transformer>
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
                    <transformer
                        implementation="org.apache.maven.plugins.shade.resource.ApacheNoticeResourceTransformer">
                        <addHeader>false</addHeader>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
</plugin>