10

I have a DropWizard REST API written and works. One of the resource endpoints actually writes an email, however as soon as I add the following dependencies DropWizard starts to fail on start up

<dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-client</artifactId>
        <version>1.18.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.18.1</version>
    </dependency>
    <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.18.1</version>
    </dependency>

The DropWizard dependency is:

<dependency>
        <groupId>io.dropwizard</groupId>
        <artifactId>dropwizard-core</artifactId>
        <version>0.8.1</version>
    </dependency>

The error on startup is really long, summarised below

    WARN  [2015-05-01 20:06:08,887] org.glassfish.jersey.internal.Errors: The following warnings have been detected: WARNING: Unknown HK2 failure detected:
MultiException stack 1 of 2
java.lang.NullPointerException
    at com.sun.jersey.core.provider.jaxb.AbstractJAXBProvider.setConfiguration(AbstractJAXBProvider.java:113)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    ....
    MultiException stack 2 of 2
java.lang.IllegalStateException: Unable to perform operation: method inject on com.sun.jersey.core.impl.provider.entity.XMLRootElementProvider$App
    at org.jvnet.hk2.internal.ClazzCreator.create(ClazzCreator.java:395)
    ....
    MultiException stack 3 of 3
java.lang.IllegalStateException: Unable to perform operation: create on org.glassfish.jersey.message.internal.MessageBodyFactory
    ...

I'm guessing DropWizard is using another conflicting dependency so how do I deal with this?

Thanks in advance

Manish Patel
  • 4,411
  • 4
  • 25
  • 48

2 Answers2

5

Dropwizard 0.8.x uses Jersey 2.x which naturally conflicts with your Jersey 1.x dependencies.

I think it might be fine with jersey-client as long as you don't have dropwizard-client dependency but jersey-core will conflict at many points with dropwizard's jersey which I don't think you can fix. And also I don't think you'd need jersey-core for sending email anyway.

If you do need jersey for this, try using Jersey 2.16 instead which is the version dropwizard is using.

Natan
  • 2,816
  • 20
  • 37
  • ok i think i just realised something painful... the code for email is written for (old?) jersey client, whereas new jersey is in the glassfish dependency - which looks completely different. Otherwise the one I have above only goes up to version 1.19 – Manish Patel May 02 '15 at 16:19
  • I had the same problem, if your parent maven project is dropwizard, you can omit the jersey version in your dependency and all is well. My parent is not dropwizard, so mvn dependency:tree will reveal the needed jersey version (for DW 0.9.3 it.s 2.22.1) – Joel Jul 21 '16 at 17:02
1

I had the same problem (I'm using DW 0.9.2 and have unwanted transitive dependencies of both DW 0.7.2 and Jersey 1.x)

The solution was pretty simple: in the dependency that's bringing you those two family of libraries, declare an exclusion and it should work, for instance, this is how I did it in Gradle:

compile("com.example.culprit:culprit:1.2.3") {
    exclude group: 'io.dropwizard'
    exclude group: 'com.sun.jersey'
}

The syntax for Maven is pretty similar (more verbose actually ;-) )

Hope this helps someone.

Clint Eastwood
  • 4,995
  • 3
  • 31
  • 27