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

조회 수: 7 (최근 30일)
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)

채택된 답변

Brian
Brian 2019년 1월 29일
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
Phil Chiu
Phil Chiu 2021년 9월 22일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Mohan Feng
Mohan Feng 2019년 1월 14일
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
Brian
Brian 2019년 1월 14일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Java Package Integration에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by