Home » Java

Generate jar with spring dependencies using maven

23 July 2015 Written by: No Comment

The issue while generating Uber jar with Spring dependencies using maven is that Jar generation is the final spring.handlers and spring.schemas does not contain all required xsd locations. The root cause for this issue is while combining all the dependecies, generation process also copies META-INF of individual jar into the Uber jar’s META-INF folder. Due to this there is a possibility that some jar’s META-INF content might be overriden by another Jar’s META-INF content if the file names are same.
As in Spring we have this issue because individual jars of spring – (spring-core.jar, spring-beans.jar, spring-expression.jar, spring-aop.jar, spring-context.jar, spring-context-support.jar, spring-jms.jar, spring-tx.jar, spring-jdbc.jar, spring-orm.jar, spring-oxm.jar, spring-web.jar, spring-webmvc.jar, spring-test.jar)

contains their own spring.handlers and spring.schemas in their META-INF folder.

I was getting below error after generating uber jar:

Caused by: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 33; cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:annotation-config'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:134)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:437)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:368)

Here is the solution for this problem -Use AppendingTransformer which will merge all spring.handlers into one file, similarly for spring.schemas file in single spring.schemas which will be copied inside META-INF/spring.schemas.

									implementation ="org.apache.maven.plugins.shade.resource.AppendingTransformer">
									implementation ="org.apache.maven.plugins.shade.resource.AppendingTransformer">

Hope this post will help you. Also please let me know if you are facing any issues which generating uber jars.

Leave your response!

Please add your comment below. Here is the trackback Link and subscribe to these comments Comment RSS Link.

Be nice. Keep this blog clean. Please dont spam.

We support Gravatar. To get your own gravatar, please register at Gravatar.