gpt4 book ai didi

java protobuf运行时正式示例不起作用

转载 作者:行者123 更新时间:2023-12-02 11:23:03 25 4
gpt4 key购买 nike

我正在尝试在 here 的 java 源中运行 protobuf 的官方示例,遵循 README.mdprotoc 生成 javasource 代码很好,但我无法通过以下方式运行代码:

1- java AddPerson 数据

2- java -cp protobuf-java-3.5.1.jar AddPerson

1- java AddPerson 数据的错误是:

Exception in thread "main" java.lang.NoClassDefFoundError: 
"com/google/protobuf/MessageOrBuilder
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at AddPerson.main(AddPerson.java:69)
Caused by: java.lang.ClassNotFoundException:
com.google.protobuf.MessageOrBuilder
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 25 more"

2-错误:java -cp target/protobuf-java-3.5.1.jar AddPerson

Error: Could not find or load main class AddPerson


[enter image description here][2]

最佳答案

尝试将当前目录包含在类路径中:java -cp .:target/protobuf-java-3.5.1.jar AddPerson

.: 是附加类路径。对于 Windows,它是 ; 而不是 :.[1]

[1] https://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

关于java protobuf运行时正式示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49792159/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com