Not able to import class in my uber JAR
    3 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
This question is the same behavioral as already asked in: Having problems using 3rd party java library, NoClassDefFoundError. Why do import commands matter? - MATLAB Answers - MATLAB Central (mathworks.com)
Hence, I can't load some 3-rd party classes which is inside my uber JAR file. I guess this can be veriifed by import in Matlab accoring to:
import 'io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder'
My uber JAR is (which contains the gRPC classes and the rest of my application) is compiled with the exactly same version as the one Matlab is using, jdk/1.8.0_202 .
Here is the code:
import io.grpc.*;
import proto.production.db.calibration.service.PushCalibrationDataServiceGrpc;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
public class SnPClient {
    private static final Logger logger = Logger.getLogger(SnPClient.class.getName());
    private final ManagedChannel channel;
    protected final PushCalibrationDataServiceGrpc.PushCalibrationDataServiceBlockingStub blockingStub;
    public SnPClient(String host, int port) {
        logger.info("Initialize SnPClient to host: " + host + ":" + port);
        channel = ManagedChannelBuilder.forAddress(host, port)
                .usePlaintext()
                .build();
        blockingStub = PushCalibrationDataServiceGrpc.newBlockingStub(channel);
        logger.info("Initialization of SnPClient successful");
    }
    public void shutdown() throws InterruptedException {
        channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
    }
}
The JAR is defined in Matlab dynamic classpath (have tried the static one as well, with same behavioral).
The SnPClient constructor is called from Matlab according to:
>> snpClient =  SnPClient("0.0.0.0", 8080);
Sep 29, 2021 8:49:32 AM SnPClient <init>
INFO: Initialize SnPClient to host: 0.0.0.0:8080
Java exception occurred:
java.lang.NoClassDefFoundError: Could not initialize class io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder
	at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
	at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
	at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:39)
	at SnPClient.<init>(SnPClient.java:15)
If you have any ideas, please let me know.
Thanks
0 Commenti
Risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
