How to avoid dependency conflict when using dropwizard + jersey client - java

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

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.

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.

Related

Getting error while using Jira rest java client

I am trying to use jira-rest-java-client-api in my Jira server plugin.
I am using following versions,
Jira - 7.13.0
jira-rest-client. Version - 5.2.0
In my pom I have added jira-rest-java-client-api and jira-rest-java-client-core dependency like,
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-api</artifactId>
<version>${jira-rest-client.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-rest-java-client-core</artifactId>
<version>${jira-rest-client.version}</version>
<scope>provided</scope>
</dependency>
I have added scope as provided so when I am building project using maven (atlas-mvn clean package) there is no error, but when I am trying to start the Jira server, my plugin is not added to Jira.
Getting following error
Unable to resolve 185.0: missing requirement [185.0]
osgi.wiring.package;
(osgi.wiring.package=com.atlassian.jira.rest.client.api)
Also, If I have not added the scope as provided then getting an error for banned dependencies while building using atlas-mvn clean package.
Any help would be appreciated, Thanks.

Connect SMB endpoint with Camel v3 and the camel-jcifs from camel-extra

I have the following maven versions in my pom.xml (among others):
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.apache-extras.camel-extra</groupId>
<artifactId>camel-jcifs</artifactId>
<version>2.25.2</version>
<exclusions>
<exclusion>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
Camel spring-boot version = 3.7.0 and I want to connect to a SMB endpoint like this:
smb://sharedriveuser#server-instance.sub.domain.net/folder?initialDelay=0&delay=9000&autoCreate=false&noop=true&idempotent=true&password=ThePassWorD&filter=#csvFileFilter
I read the Camel 3 Migration Guide and found nothing regarding this camel-extras.
When trying to connect, I get an error like the password option is not supported anymore:
Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve endpoint: smb://sharedriveuser#server-instance.sub.domain.net/folder?initialDelay=0&delay=9000&autoCreate=false&noop=true&idempotent=true&password=xxxxxx&filter=#csvFileFilter due to: There are 1 parameters that couldn't be set on the endpoint. Check the uri if the parameters are spelt correctly and that they are properties of the endpoint. Unknown parameters=[{password=ThePassWorD}]
The actual documentation link google found many times, seems dead.
From Maven central, there is no version 3.x of the lib camel-jcifs and I am wondering if the lib is still compatible with Camel 3.x.x, otherwise is there another alternative with Camel 3?
I also tried to downgrade the camel-jcifs to 2.24.3 with the same error.
Camel-extras is a separated project from the Apache Camel. There is some work in place in the camel-extra repository to support camel 3[1], but it is still to be completed and there is no release in sight.
[1] https://github.com/camel-extra/camel-extra/commit/f028dfdfaa467958c58abea0d604f8fe2f17be04
There is now a pull request to add camel-jcifs to the 3.x version:
https://github.com/camel-extra/camel-extra/pull/39
You might also get my fork and build it yourself:
https://github.com/bebbo/camel-extra *
It got merged and is in the official repository:
https://github.com/camel-extra/camel-extra
To use it with quarkus, you have to convert some List types to arrays.

NoSuchMethodError on startup in Java Jersey app

I've been getting a very strange error when trying to start a Jersey app on Tomcat. The same code works on other computers. I tried reinstalling tomcat, all my maven dependencies, even Eclipse and Java itself, no luck. It seems like a bad Jersey version is being loaded, I think?
Any pointers in the right direction will be appreciated.
Here's the effective pom: http://pastebin.com/NacsWTjz
And the actual pom: http://pastebin.com/H6sHe4ce
2015-02-13 13:43:40,870 [localhost-startStop-1] ERROR org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/middleware-server] - StandardWrapper.Throwable
java.lang.NoSuchMethodError: javax.ws.rs.core.Application.getProperties()Ljava/util/Map;
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:304)
at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:285)
at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:311)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:358)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1231)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1144)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1031)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4901)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5188)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Note: Please see above comments for further discussion and tips.
This error usual means that you have a both a JAX-RS 1 and JAX-RS 2 jar on the classpath. Jersey 2 uses JAX-RS 2 (javax.ws.rs-api-2.0.1.jar), but if you have the jsr311-api.jar also, which is JAX-RS 1, there is a javax.ws.rs.core.Application in each jar. But the jsr311-api Application doesn't have the method getProperties() (hence NoSuchMethodError).
I've come to the conclusion that all you need to do is add the above exclusion to the swagger dependency. The Jackson 2.0 provider (which depends on JAX-RS 1) seems to be overridden by a 2.4.1 provider (which uses the new version). So we don't need to add it ourselves. When it's overridden, it seems to leave behind the jsr311-api.jar. So if we exclude it, no one can attempt to use it, which looks to be the current problem
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.10</artifactId>
<version>1.3.11</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
We are using jersey-json 1.9 which has a dependency on jersey-core which also happen to have a javax.ws.rs.core.Application class.
So our fix is to exclude the jersey-core from jersey-json:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.9</version>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
the problem is related about "com.sun.jersey:jersey-core:jar:1.18.3" (or any 1.* version) because old versions of Jersey didn't have that "public Map getProperties()" method.
And one of your dependencies use Jersey version 1 (you can check that in running mvn dependency:tree and search all jersey-core version used)
Me I have resolved the problem deleting all com.sun.jersey dependancies (old api) and using the new one org.glassfish.jersey API
https://mvnrepository.com/artifact/org.glassfish.jersey.core

java.lang.NoClassDefFoundError error when running my project

I have been struggling to get this to work and I think i can use some help. I am working on a Java project where the pom.xml has a bunch of dependencies some of which are themselves indirectly dependent on this jar:
com.sun.jersey:jersey-core:1.17.1 like this:
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.0.1</version>
</dependency>
And I need this particular jar in my pom because I want to use the new features in jax-rs api:
javax.ws.rs:javax.ws.rs-api:2.0.The problem is when I build my project I get this error:
Found duplicate classes in [com.sun.jersey:jersey-core:1.17.1,javax.ws.rs:javax.ws.rs-api:2.0] :
[WARNING] javax.ws.rs.ApplicationPath
[WARNING] javax.ws.rs.Consumes
[WARNING] javax.ws.rs.CookieParam
[WARNING] javax.ws.rs.DELETE
[WARNING] javax.ws.rs.DefaultValue
[WARNING] javax.ws.rs.Encoded
[WARNING] javax.ws.rs.FormParam
[WARNING] javax.ws.rs.GET
[WARNING] javax.ws.rs.HEAD
[WARNING] javax.ws.rs.HeaderParam
...
..
I tried to fix this by excluding com.sun.jersey:jersey-core:1.17.1 from dependencies which were including it by checking the dependency tree.
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.0.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
</exclusion>
</exclusions>
</dependency>
Now the project builds fine but when I try to run it I get this error:
java.lang.NoClassDefFoundError: com/sun/jersey/core/util/FeaturesAndProperties
at java.lang.Class.getDeclaredMethods0(Native Method) ~[na:1.7.0_51]
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531) ~[na:1.7.0_51]
at java.lang.Class.getDeclaredMethods(Class.java:1855) ~[na:1.7.0_51]
at com.google.inject.internal.ProviderMethodsModule.getProviderMethods
(ProviderMethodsModule.java:81) ~[guice-3.0.jar:na]
at com.google.inject.internal.ProviderMethodsModule.configure
(ProviderMethodsModule.java:73) ~[guice-3.0.jar:na]
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
~[guice-3.0.jar:na]
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:232)
~[guice-3.0.jar:na]
at com.google.inject.spi.Elements.getElements(Elements.java:101) ~[guice-3.0.jar:na]
at com.google.inject.spi.Elements.getElements(Elements.java:92) ~[guice-3.0.jar:na]
It seems like jersey core was needed but how do I get around this problem?
You can't mix JAX-RS / Jersey versions
Jersey version 1 is the reference implementation for JAX-RS 1. Jersey version 1 uses the com.sun.jersey group / package prefix.
Jersey version 2 is the reference implementation for JAX-RS 2. Jersey version 2 uses the org.glassfish.jersey group / package prefix
If you have both Jersey versions, or both JAX-RS versions on your classpath, you'll get lots of NoClassDefFoundError, NoSuchMethodError or similar.
If possible use JAX-RS / Jersey version 2
For me this actually means I had somehow mixed things and was using
$ mvn dependency:list | grep jersey
[INFO] com.sun.jersey:jersey-client:jar:1.11:compile
[INFO] com.sun.jersey:jersey-core:jar:1.0.2:compile
(conflict within jersey 1.x)
Jersey is the reference implementation of JAX-RS, so you don't need the latest version of JAX-RS API (javax.ws.rs:javax.ws.rs-api:2.0) but the latest version of Jersey which is 2.8 (see https://jersey.java.net/).

Does JAXB work under Java 5?

Building with maven I get "package javax.xml.bind.annotation does not exist"
What do I need to make JAXB work with Java 5?
JAXB APIs are bundled in JDK1.6, but these are not available in JDK <1.6 (ex: JDK1.5).
I have a Java to XML code written in JDK1.6 and once I switched to JDK1.5, I got the following error:
*Exception in thread "main" java.lang.RuntimeException: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]
...
Caused by: javax.xml.bind.JAXBException
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory]*
...
JDK1.5 doesnt contain the JAXB APIs and therefore I applied the following fix:
I used JDK1.5 and the following two JARS: jaxb-api-2.0.jar and jaxb-impl-2.0.jar in my classpath and the error was resolved.
I hope this helps.
Another Reference: http://www.mkyong.com/java/jaxb-hello-world-example/
You can download the reference implementation (RI) from http://jaxb.dev.java.net/.
I can't advise you on how to make it work with maven though - more trouble than it's worth, if you ask me.
Java6 included a slightly modified version of the RI, but the RI itself works just fine with Java5.
Using the following versions will work with JDK5:
<!--
versions after 2.2.4 requires jdk6, please refer
to https://java.net/jira/browse/JAXB-890
-->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2.4-1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.3</version>
</dependency>
It seems there are many versions and differing paths to get JAXB from a maven repository.
My best guess for the correct artifact is javax.xml.bind:jaxb-api:2.2
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2</version>
<scope>compile</scope>
</dependency>
Jaxb should work with Java 5 but it seems that there are more people having issues with it.
Could it be that are missing some jars?
Check out this forum post.

Categories

Resources