My day had been completely wasted. So I decided that a blog post can’t make it any worse. Everything started when I typed
gradlew deployServer Then I spent some semi-funny time.When this fun was over the server would not start anymore… An obscure
NullPointerException was thrown somewhere deep in the core libs when the following code got executed
The stack trace looked as ugly as this:
Please read carefully –
javax.xml.bind.JAXBContext. But… this is part of the JDK! So now what? Stunned…. Google to the rescue? No, let’s make it more entertaining. The debugger is waiting there for me, why not enter under the hood of the JDK? Excellent opportunity! The problem was that I soon found out that the JDK sources mismatch the class that I was debugging. Blah! What is going on?
After a quick look at
cartrides/lib I found this lib
javax.xml.bind.jaxb-api-2.2.2.jar. Nasty… Going back to google I discovered that there is a small bug and JAXB sometimes behaves really nasty (null pointers) when there are two conflicting reference implementations in the classpath. But how to find which caused the conflicting dependency?
dependencies task in my assembly came to the rescue:
Oh, nooo – jersey is the culprit!!! Apparently the
jaxb-api is a transitive dependency introduced by jersey. At this moment I almost felt desperate because we have a huge amount of infrastructure built upon the jersey client (which needs jersey JSON). We need jersey to continue! Our connector uses it to consume RESTful services. But why it needs JAXB reference implementation? I decided to browse a little bit the documentation of Jersey 1.19.
XML serialization support of Java types that are JAXB beans requires a dependency on the JAXB reference implementation version 2.x or higher.
Deploying an application for XML serialization support requires no additional dependencies, since Java SE 6 ships with JAXB 2.x support.
Here I’ve found more details about which JAXB RI is included in which Java SE.
Summary: it seems to me that the whole machinery is necessary so that the JSON serialization of JAXB annotated classes work with pre-Java 1.6 versions.
Which means that the dependency may be explicitly excluded from my build.
After a couple of chats I realized that with the current gradle version we can do that only on assembly level (because there is a little hack kindly provided in our gradle plugins). Here is what needs to be added:
The server finally started smoothly. But I failed to login… Someone added a new column in the DB. Time for a DBInit…