amazon-kinesis-producer icon indicating copy to clipboard operation
amazon-kinesis-producer copied to clipboard

NoClassDefFoundError: javax/xml/bind/DatatypeConverter with amazon-kinesis-producer 0.14.13 on JDK 11

Open vsadokhin opened this issue 2 years ago • 8 comments

Hello

I experience NoClassDefFoundError: javax/xml/bind/DatatypeConverter during build/tests if amazon-kinesis-producer version bumped from 0.14.12 to 0.14.13. The stacktrace says:

Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
	at com.amazonaws.services.kinesis.producer.HashedFileCopier.copyFileFrom(HashedFileCopier.java:56)
	at com.amazonaws.services.kinesis.producer.KinesisProducer.extractBinaries(KinesisProducer.java:1025)
	at com.amazonaws.services.kinesis.producer.KinesisProducer.<init>(KinesisProducer.java:298)
	at ...

According to maven dependencies 0.14.13 brings jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0 and my IDE shows that it has DatatypeConverter but from jakarta.xml.bind package. However, HashedFileCopier from amazon-kinesis-producer:0.14.13 imports javax.xml.bind.DatatypeConverter and that one indeed missed.

Please, find my questions below: Is it correct that HashedFileCopier refers to javax.xml.bind.DatatypeConverter? Will it be changed / fixed in the feature releases of amazon-kinesis-producer? What is the recommended way to bypass the issue now? (I guess provide a dependency with javax.xml.bind.DatatypeConverter)

Thank you in advance!

King Regards, Vasiliy

vsadokhin avatar Oct 04 '22 05:10 vsadokhin

https://github.com/awslabs/amazon-kinesis-producer/pull/449/commits/c2adf14dfe59a9515f38a25764954a1133c72a66

Looks relevant

vsadokhin avatar Oct 04 '22 10:10 vsadokhin

any idea how to fix this error? running java 17 and have the same problem with Kinesis producer.

MeesvanStraten avatar Oct 21 '22 13:10 MeesvanStraten

@MeesvanStraten you can try building the producer jar from local changing: import javax.xml.bind.DatatypeConverter; to import jakarta.xml.bind.DatatypeConverter; And replace the jar in your maven m2 folder.

Alternatively, try adding in the following dependencies in the pom.xml?

        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.0</version>
        </dependency>

superfive666 avatar Oct 25 '22 05:10 superfive666

@superfive666 if that's the local fix, maybe we can aim the official build/maven artifact to incorporate those changes?

@MeesvanStraten does building the producer yourself with the suggestion fix it for you locally?

lc-nyovchev avatar Oct 25 '22 11:10 lc-nyovchev

@lc-nyovchev Adding the javax.xml.bind package myself works. It has something to do with the package not being included from Java 9.

This stack overflow helped me understanding better

MeesvanStraten avatar Oct 25 '22 12:10 MeesvanStraten

Hello folks, this issue should be fixed by this commit: https://github.com/awslabs/amazon-kinesis-producer/commit/7e6203dccc6bf55b496098571b491d22f3507335

zengyu714 avatar Jan 04 '23 17:01 zengyu714

@zengyu714 hi, I understand the fix in terms of supporting older Java. If I look at the code and why it is used it is basically (ignoring the sample app) for converting binary to hex. Not sure how you guys are on dependencies, but perhaps depending on https://commons.apache.org/proper/commons-codec/archives/1.15/apidocs/index.html encodeHex which to my believe should bring the same functionality would remove the need for depending on xml.bind all together

kbos-work avatar Jan 04 '23 21:01 kbos-work

or another alternative, because I am also not a fan to depend just for a single thing on some library is to have this logic within the repository. Looking at the original source of printHexBinary (https://github.com/javaee/jaxb-spec/blob/master/jaxb-api/src/main/java/javax/xml/bind/DatatypeConverterImpl.java) it doesn't seem to dramatic to support within the repo with proper tests

kbos-work avatar Jan 04 '23 21:01 kbos-work