Having problems using 3rd party java library, NoClassDefFoundError. Why do import commands matter?

5 Ansichten (letzte 30 Tage)
I am working to get grpc-java to work in matlab. I have all the jar files I need in a directory, and to verify I was able to use javac to build and run an appication using this directory. The problem I have is if I try to run one of the grpc-java examples within matlab I get various NoSuchMethodError, or NoClassDefFoundError. What is interesting is I can get around the first NoSuchMethodError by adding an extra 'import io.grpc.ManagedChannelProvider' that is not part of the original example. But in the end I still get the error below. So my 2 questions are, 1) How can I figure out what is wrong here? 2) Why would I have to add an 'import' command if everything builds/runs fine on command line? But if this is the case, I guess my error would be fixed by adding another 'import' command, but how to figure out which one?
https://github.com/grpc/grpc-java/blob/master/examples/src/main/java/io/grpc/examples/helloworld/HelloWorldClient.java
>> o = ManagedChannelBuilder.forAddress('localhost', 5001)
Java exception occurred:
java.lang.NoClassDefFoundError: Could not initialize class io.grpc.netty.NettyChannelBuilder
at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
at io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:37)

Akzeptierte Antwort

Brian
Brian am 29 Jan. 2019
I have been working with Mathworks, and it turns out this is a problem with different versions of guava being used for my library, and matlab's internal use. And there is no workaround. :(.
  1 Kommentar
Phil Chiu
Phil Chiu am 22 Sep. 2021
This is not related to gRPC specifically, but in the past, I have worked around version conflicts between Matlab's bundled libraries and my own Java libraries by building an "uber-JAR" for my desired library, which bundles and "shades" all of its dependencies under different names. Maven can do this shading for you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Mohan Feng
Mohan Feng am 14 Jan. 2019
A possible reason of this issue is that you did not add all JAR files into MALTAB JAVA class path. You could refer to the answer in the following link to try to add all JAR files into static or dynamic MATLAB JAVA class path.
  1 Kommentar
Brian
Brian am 14 Jan. 2019
That is just it, I do have all the jar files in the static class path, as I can even do a 'methods ...' to all the classes and methods show up. Also I built/ran from the command line with a standalone java class with just those same jar files, and everything runs fine.

Melden Sie sich an, um zu kommentieren.

Tags

Produkte


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by