当我在.proto中使用描述符时,我像
import "google/protobuf/descriptor.proto";message AddressBook { required google.protobuf.FileDescriptorSet proto_files = 1;
然后使用默认目录下的addressbookSD.proto生成Java(在Windows上):
protoc addressbookSD.proto --java_out=./ --proto_path=./ --proto_path=<protobuf-install-directory>src
其中,< protobuf-install-directory >是协议缓冲区安装目录。关键是描述符.proto在
<protobuf-install-directory>srcgoogleprotobuf
protobuf导入策略中的级别必须与文件系统中的目录匹配,就像在Java中一样。
因此,我使用< protobuf-install-directory > src作为导入目录,目录结构必须为
<protobuf-install-directory>src +-- google +-- protobuf +-- descriptor.proto
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)