英文:
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:
<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
得分: 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.
<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>
replace com.mafei.server.GRPCServer
with your main class of the project.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论