0

I am new to Docusign and trying to use the Java Client However I run into the following error when trying to use code from the recipes -

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.sun.jersey.core.header.MediaTypes
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:182)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.initReaders(MessageBodyFactory.java:176)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.init(MessageBodyFactory.java:162)
at com.sun.jersey.api.client.Client.init(Client.java:343)
at com.sun.jersey.api.client.Client.access$000(Client.java:119)
at com.sun.jersey.api.client.Client$1.f(Client.java:192)
at com.sun.jersey.api.client.Client$1.f(Client.java:188)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
at com.sun.jersey.api.client.Client.<init>(Client.java:188)
at com.sun.jersey.api.client.Client.<init>(Client.java:160)
at com.sun.jersey.api.client.Client.create(Client.java:673)
at com.docusign.esign.client.ApiClient.getClient(ApiClient.java:671)
at com.docusign.esign.client.ApiClient.getAPIResponse(ApiClient.java:429)
at com.docusign.esign.client.ApiClient.invokeAPI(ApiClient.java:543)
at com.docusign.esign.api.AuthenticationApi.login(AuthenticationApi.java:147)

The jars that I included to resolve some dependency issues are -

com.fasterxml.jackson.core/jars/jackson-annotations-2.4.2.jar
com.fasterxml.jackson.core/jars/jackson-core-2.4.2.jar
com.fasterxml.jackson.core/jars/jackson-databind-2.4.2.jar
com.fasterxml.jackson.datatype/jars/jackson-datatype-joda-2.1.5.jar
io.swagger/jars/swagger-annotations-1.5.4.jar
com.sun.jersey.contribs/jars/jersey-multipart-1.18.jar
com.sun.jersey/jars/jersey-bundle-1.19.jar
com.brsanthu/jars/migbase64-2.2.jar
com.docusign.esign/jars/com-docusign-esign-15.4.0.jar
user5807897
  • 11
  • 1
  • 3

3 Answers3

5

You don't have jersey-core jar. You can download the jar from here

Balwinder Singh
  • 2,272
  • 5
  • 23
  • 34
  • 1
    Thanks for the response, but the jersey-bundle-1.19.jar has the class. I anyway attempted to add the jersey-core jar but it did not work. Do you recommend replacing the jersey-bundle with other jars? – user5807897 Jan 19 '16 at 17:11
  • 1
    @user5807897 If it already has the class; then double-check on whether you have included the given jar in classpath or not – Balwinder Singh Jan 19 '16 at 23:15
  • I replaced the jersey-bundle with – user5807897 Jan 19 '16 at 23:38
  • @user5807897 with jersey-core.jar I presume?? – Balwinder Singh Jan 19 '16 at 23:39
  • I replaced the jersey-bundle by including **jsr311-api-1.1.jar, jersey-client-1.18.jar, jersey-core-1.19.jar**. I added breakpoints to MessageBodyFactory method initReader and it results in this error when it comes across the following _MediaTypes.createMediaTypes((Consumes)i$.getClass().getAnnotation(Consumes.class));_ MessageBodyFactory is also a class that exists in jersey-core. So it is present in the classpath. – user5807897 Jan 19 '16 at 23:45
  • @user5807897 Still the same error? Have you added the jars in classpath? – Balwinder Singh Jan 20 '16 at 00:04
  • Yes, the jars are present in the classpath. I assume it would not be able to find MessageBodyFactory as well if jersey-core was missing in the classpath. – user5807897 Jan 20 '16 at 00:17
  • @user5807897 That's strange. Perhaps you should have a look at http://stackoverflow.com/questions/17973970/how-to-solve-java-lang-noclassdeffounderror link and see what can be done to avoid this. – Balwinder Singh Jan 20 '16 at 00:21
  • Are there other things listed in your Java `classpath` that might be pulling in older or deprecated jars? Also, I know a common problem in eclipse is the order in which you add things, you might want to try going into your project settings then Java Build Path, remove the JRE system library, then simply add it back in and that sometimes resolves issues like these. – Ergin Jan 20 '16 at 01:00
  • I have encountered similar problems with Eclipse in the past, however now I am on IntelliJ. I tried removing and adding those jars back but that has not resolved my issue. – user5807897 Jan 20 '16 at 19:48
1

Adding javax.ws.rs-api-2.0.1.jar resolved my NoClassDefFoundError. This jar does not get listed in the maven dependency tree. A Junit test for the com.sun.jersey.core.header.MediaTypes class as shown below helped me get a descriptive error message.

public class MediaTypesTest extends TestCase {

    public void testLoadClass() throws Exception {
        MediaTypes.getTypeWildCart(MediaType.MULTIPART_FORM_DATA_TYPE);

    }
}
user5807897
  • 11
  • 1
  • 3
0

First of all welcome to DocuSign community! I am sorry to hear that you have dependency issues. I will glad to help you to fix it.

In order to make DocuSign Java developers life easier, we have published a brand new Maven package. Please go to this page and you will find all the information that you need, in order to get up and running with the Java client: http://mvnrepository.com/artifact/com.docusign/docusign-esign-java/2.0.0.

As you will see, the jersey-client and jersey-multipart version is 1.18.

If you are using Pom, Gradle, or any other build system that supports remote package dependency resolving, then you can drop the packages that are in your lib folder, and use the Maven package. Your build management software (Pom or Gradle), will be able to resolve the dependencies automagically.

  • For Pom:

<dependency>
 <groupId>com.docusign</groupId>
 <artifactId>docusign-esign-java</artifactId>
 <version>2.0.0</version>
</dependency>
  • For Gradle: 'com.docusign:docusign-esign-java:2.0.0'

If you still have trouble, please let me know how you added the dependencies to your Java project and I will be glad to help.

Cheers,

Majid

Majid Mallis
  • 114
  • 4
  • Thanks for pointing out the new Java Client. The jars I now have in my classpath are docusign-esign-java-2.0.0.jar and the dependency jars specified in Compile dependency section of [link](http://mvnrepository.com/artifact/com.docusign/docusign-esign-java/2.0.0). Now I run into the following error - 'Caused by: java.lang.NoClassDefFoundError: com/sun/jersey/spi/inject/Errors$Closure at com.docusign.esign.client.ApiClient.getClient(ApiClient.java:671) at com.docusign.esign.client.ApiClient.getAPIResponse(ApiClient.java:429) at com.docusign.esign.client.ApiClient.invokeAPI' – user5807897 Jan 20 '16 at 19:45
  • Please Note now there is no jersey-core in my classpath. – user5807897 Jan 20 '16 at 19:49
  • Well, if you choose to download the new java client and its dependencies, you will need to make sure that the DocuSign dependencies have their dependencies in the project as well...and so on. That's why using Pom. Build management tools will do this manual work for you and go through the tree of dependencies till the end. So in your case, it looks like you're missing two dependencies. (jersey-core is still required for jersey-client and jersey-multi-part): **jersey-core:1.18** **mimepull:1.9.3** – Majid Mallis Jan 20 '16 at 20:15
  • Thanks for the dependency tree. I had looked it a little while ago and verified that all the jars are present. Wrote a Junit test for the com.sun.jersey.core.header.MediaTypes class, that returned a descriptive error message. Added **javax.ws.rs-api-2.0.1.jar** and that resolved my NoClassDefFoundError. – user5807897 Jan 20 '16 at 21:54
  • Hi, Thank you for pointing out the missing dependency. It looks like it's required on some environments (like Android Studio). So I have included it and published a new Maven package. So now if you using Maven, it will also download javax.ws.rs-api-2.0.1.jar Thank you for the feedback! – Majid Mallis Jan 27 '16 at 02:09