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

huangapple go评论74阅读模式
英文:

java grpc issue - java.lang.NoClassDefFoundError: io/grpc/BindableService

问题

这些是OpenShift部署过程中的日志:

开始使用 /opt/jboss/container/java/run/run-java.sh 启动 Java 应用程序...
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 位 Server VM 警告:如果预计处理器数量将从一个增加到多个,则应使用 -XX:ParallelGCThreads=N 适当地配置并行 GC 线程数。
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 解决了这个问题:
https://stackoverflow.com/questions/42540531/bindableservice-issue-with-grpc-java
但不幸的是,我需要使用 Maven。

提前感谢您提供的所有信息。

英文:

That are logs from openshift deploying:

    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

It looks i have imported all needed dependencies. I also found out how one man fixed this issue with gradle:
https://stackoverflow.com/questions/42540531/bindableservice-issue-with-grpc-java
But unfortunatelly i need to have maven.

Thanks for all infos in advance

答案1

得分: 2

你的 grpc jars 可能没有捆绑在一起。您可以使用以下方法创建一个包含所有依赖的 fat 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>完整的主类名</mainClass>
               </manifest>
            </archive>
         </configuration>
         <executions>
            <execution>
               <phase>package</phase>
               <goals>
                  <goal>single</goal>
               </goals>
            </execution>
         </executions>
      </plugin>
   </plugins>
</build>
英文:

Your grpc jars might not be bundled. You can create a fat jar using the following:

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





答案2

得分: 2

            <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>你的项目的主类路径</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

com.mafei.server.GRPCServer替换为你项目的主类路径。

英文:

change the plugins sections of your pom.xml file like below.

            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-shade-plugin&lt;/artifactId&gt;
                &lt;version&gt;3.2.4&lt;/version&gt;
                &lt;executions&gt;
                    &lt;execution&gt;
                        &lt;phase&gt;package&lt;/phase&gt;
                        &lt;goals&gt;
                            &lt;goal&gt;shade&lt;/goal&gt;
                        &lt;/goals&gt;
                        &lt;configuration&gt;
                            &lt;transformers&gt;
                                &lt;transformer
                                        implementation=&quot;org.apache.maven.plugins.shade.resource.ManifestResourceTransformer&quot;&gt;
                                    &lt;mainClass&gt;com.mafei.server.GRPCServer&lt;/mainClass&gt;
                                &lt;/transformer&gt;
                            &lt;/transformers&gt;
                        &lt;/configuration&gt;
                    &lt;/execution&gt;
                &lt;/executions&gt;
            &lt;/plugin&gt;

replace com.mafei.server.GRPCServer with your main class of the project.

huangapple
  • 本文由 发表于 2020年3月15日 08:05:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/60688528.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定