Recently I’ve had a problem where my jar file created by gradle ran differently than my configuration in eclipse, it didn’t take my very long to determine that problem, but rather I don’t know how to fix the problem in gradle.
Problem:
I’m running an embedded jetty in my desktop app and using resteasy as a restful framework. When I jar up my program it says that a JSON provider could not be found. The reason why it couldn’t find it is because I have more than one javax.ws.rs.ext.Providers file in my META-INF/services folder.(It looked like it did read the first one it found but my jettison provider wasn’t in the top file).
I verified that this was the problem by taking all the contents of the 3 files, combining them into one file, then deleting the 3 files and then adding my one combined file back to the jar, I ran the jar and it worked as expected.
So I understand the problem but I don’t have the experience in gradle to fix the problem, I was wondering if any of you had an idea for the solution to take any duplicates in the META-INF/services folder and combine the results for those files… I would think that it would be safe to merge them in all cases with the exception of the duplicate files maybe having duplciate services declared and in that case you would also have to root out duplicates again and just have the service declared once.
Here is my jar code in gradle
jar {
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
manifest {
attributes("Main-Class": project.mainClass, "Implementation-Version": project.version)
}
}
Here is what the contents of one of the Providers file looks like
org.jboss.resteasy.plugins.providers.DataSourceProvider
org.jboss.resteasy.plugins.providers.DocumentProvider
org.jboss.resteasy.plugins.providers.DefaultTextPlain
org.jboss.resteasy.plugins.providers.StringTextStar
org.jboss.resteasy.plugins.providers.InputStreamProvider
org.jboss.resteasy.plugins.providers.ByteArrayProvider
org.jboss.resteasy.plugins.providers.FormUrlEncodedProvider
org.jboss.resteasy.plugins.providers.FileProvider
org.jboss.resteasy.plugins.providers.StreamingOutputProvider
org.jboss.resteasy.plugins.providers.IIOImageProvider
org.jboss.resteasy.plugins.interceptors.CacheControlInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.ClientContentEncodingHeaderInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.ServerContentEncodingHeaderInterceptor
and another file
org.jboss.resteasy.plugins.providers.jaxb.json.JsonCollectionProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JsonMapProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JsonJAXBContextFinder
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonElementProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonXmlRootElementProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonXmlSeeAlsoProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonXmlTypeProvider
so those would combine to look like this
org.jboss.resteasy.plugins.providers.DataSourceProvider
org.jboss.resteasy.plugins.providers.DocumentProvider
org.jboss.resteasy.plugins.providers.DefaultTextPlain
org.jboss.resteasy.plugins.providers.StringTextStar
org.jboss.resteasy.plugins.providers.InputStreamProvider
org.jboss.resteasy.plugins.providers.ByteArrayProvider
org.jboss.resteasy.plugins.providers.FormUrlEncodedProvider
org.jboss.resteasy.plugins.providers.FileProvider
org.jboss.resteasy.plugins.providers.StreamingOutputProvider
org.jboss.resteasy.plugins.providers.IIOImageProvider
org.jboss.resteasy.plugins.interceptors.CacheControlInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.AcceptEncodingGZIPInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.ClientContentEncodingHeaderInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.GZIPEncodingInterceptor
org.jboss.resteasy.plugins.interceptors.encoding.ServerContentEncodingHeaderInterceptor
org.jboss.resteasy.plugins.providers.jaxb.json.JsonCollectionProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JsonMapProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JsonJAXBContextFinder
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonElementProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonXmlRootElementProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonXmlSeeAlsoProvider
org.jboss.resteasy.plugins.providers.jaxb.json.JettisonXmlTypeProvider
Thank you for taking the time to look at and consider this problem.