java grpc 问题 - java.lang.NoClassDefFoundError: io/grpc/BindableService

问题描述 投票:0回答:3

这是来自 openshift 部署的日志:

    Starting the Java application using /opt/jboss/container/java/run/run-java.sh ...
INFO exec  java -javaagent:/opt/jboss/container/jolokia/jolokia.jar=config=/opt/jboss/container/jolokia/etc/jolokia.properties -XX:+UseParallelOldGC -XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20 -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -XX:MaxMetaspaceSize=100m -XX:+ExitOnOutOfMemoryError -cp "." -jar /deployments/demo-0.0.1-SNAPSHOT.jar  
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
a
Exception in thread "main" java.lang.NoClassDefFoundError: io/grpc/BindableService
    at com.example.demo.DemoApplication.main(DemoApplication.java:18)
Caused by: java.lang.ClassNotFoundException: io.grpc.BindableService
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 1 more

看起来我已经导入了所有需要的依赖项。我还发现一个人如何用 gradle 解决这个问题: grpc-java 的 bindableService 问题 但不幸的是我需要有 Maven。

感谢您提前提供所有信息

java maven dependencies grpc shadow
3个回答
2
投票

您的 grpc jar 可能未捆绑。您可以使用以下命令创建一个胖罐子:

<build>
   <plugins>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-assembly-plugin</artifactId>
         <version>3.1.1</version>
         <configuration>
            <descriptorRefs>
               <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <archive>
               <manifest>
                  <mainClass>fully qualified main class name</mainClass>
               </manifest>
            </archive>
         </configuration>
         <executions>
            <execution>
               <phase>package</phase>
               <goals>
                  <goal>single</goal>
               </goals>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>






2
投票

更改

plugins
文件的
pom.xml
部分,如下所示。

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.4</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>com.mafei.server.GRPCServer</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

com.mafei.server.GRPCServer
替换为您的项目主类。


0
投票
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.2.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                    </configuration>
                </execution>
            </executions>
        </plugin>
© www.soinside.com 2019 - 2024. All rights reserved.