{"id":12272,"date":"2012-09-20T13:39:00","date_gmt":"2012-09-20T12:39:00","guid":{"rendered":"https:\/\/touk.pl\/blog\/?guid=ab071c3031f239f8b26dd8f0ab0b776b"},"modified":"2022-08-03T08:56:37","modified_gmt":"2022-08-03T06:56:37","slug":"classloader-problem-with-java-7-and-webservices-in-grails-2","status":"publish","type":"post","link":"https:\/\/touk.pl\/blog\/2012\/09\/20\/classloader-problem-with-java-7-and-webservices-in-grails-2\/","title":{"rendered":"Classloader problem with Java 7 and WebServices in Grails"},"content":{"rendered":"<p>Our Grails 2.1 application communicates with external SOAP WebServices. It worked fine as we follow Software Guy&#8217;s advices from <a href=\"http:\/\/asoftwareguy.com\/2012\/02\/25\/web-service-clients-where-grails-lost-its-mojo\/\">this blog post<\/a>.<\/p>\n<p>Recently, our client required new functionality &#8211; export to Excel. We&#8217;ve used <a href=\"http:\/\/poi.apache.org\/\">Apache POI<\/a> libraries for export. <strong>And our web service communication died.<\/strong> All it gave us was:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Caused by: java.lang.LinkageError: loader constraint violation: when resolving field \"DATETIME\" the class loader (instance of org\/codehaus\/groovy\/grails\/cli\/support\/GrailsRootLoader) of the referring class, javax\/xml\/datatype\/DatatypeConstants, and the class loader (instance of &lt;bootloader&gt;) for the field's resolved type, ants, have different Class objects for that type&lt;\/bootloader&gt;<\/pre>\n<p>This message is strange, LinkageError can give you creeps. But read carefully: <strong>resolved type, ants<\/strong>? Something is definitely wrong here. After many searches it turned out that Java 7 already contains some conflicting classes from stax-api.jar. To solve this problem there are two thing you need to do:<\/p>\n<ol>\n<li>Ensure that your jaxws-rt dependency is runtime, not compile! \/\/ <a href=\"http:\/\/asoftwareguy.com\/2012\/02\/25\/web-service-clients-where-grails-lost-its-mojo\/\">http:\/\/asoftwareguy.com\/2012\/02\/25\/web-service-clients-where-grails-lost-its-mojo\/<\/a><br \/>\n\/\/ Do not remove this dependency. Web services need this to work flawlessly.<br \/>\nruntime (&#8216;com.sun.xml.ws:jaxws-rt:2.1.4&#8217;)<\/li>\n<li>Create dependency report (<code>grails dependency-report<\/code>), search and exclude all stax-api dependencies other than jaxws-rt like this example:\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">compile ('org.apache.poi:poi-ooxml-3.7') {\r\n    excludes 'stax-api'\r\n}\r\ncompile ('org.apache.poi:poi-ooxml-schemas:3.7') {\r\n    excludes 'stax-api'\r\n}<\/pre>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"Our Grails 2.1 application communicates with external SOAP WebServices. It worked fine as we follow Software Guy&#8217;s advices from this blog post. Recently, our client required new functionality &#8211; export to Excel. We&#8217;ve used Apache POI libraries for expor&#8230;\n","protected":false},"author":37,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[594,50,68,381,382],"class_list":{"0":"post-12272","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-development-design","7":"tag-api","8":"tag-groovy","9":"tag-java","10":"tag-soap","11":"tag-web-service"},"_links":{"self":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12272","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/users\/37"}],"replies":[{"embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/comments?post=12272"}],"version-history":[{"count":5,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12272\/revisions"}],"predecessor-version":[{"id":14887,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/posts\/12272\/revisions\/14887"}],"wp:attachment":[{"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/media?parent=12272"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/categories?post=12272"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/touk.pl\/blog\/wp-json\/wp\/v2\/tags?post=12272"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}