协议缓冲区:如何导入? [英] Protocol Buffer: How to import?
问题描述
我有2个.proto文件:
I have 2 .proto files :
第一个文件:
package com.test.model;
message ProtoModel {
required CustomObj custom=1;
}
第二档:
package com.test.model;
message CustomObj {
required string smth=1;
}
这里的问题是CustomObj被称为未解析的参考 。
因此,我试图将第二个文件导入第一个文件:
The issue here is that "CustomObj" is said to be "unresolved reference" . Thus, I've tried to import the second file into first file:
import "com/test/model/firstFile.proto"
package com.test.model;
message ProtoModel {
required CustomObj custom=1;
}
我仍然遇到同样的问题!!
I still get the same issue !!
推荐答案
import语句是相对于您调用 protoc
的地方的文件夹。
看起来你已将它视为相对于包而言。
The import statement is the folder relative to the place where you invoke protoc
.
It looks like you have treated it as relative to the package instead.
例如。如果(像我一样)你将这两个文件存储在 src / main / resources
中,你可以按如下方式调用protoc:
e.g. if (like me) you store both files in src/main/resources
, you'd invoke protoc as follows:
protoc src/main/resources/firstFile.proto src/main/resources/secondFile.proto --java_out=src/generated/java
并且您的import语句将是 importsrc / main / resources / firstFile.proto
and your import statement would be import "src/main/resources/firstFile.proto"
如果您想根据包名将文件存储在子文件夹中,那么您只需在顶级foldername之后相应地添加它。
If you want to store the files in subfolders according to package name, then you just add this accordingly, after the top-level foldername.
HTH
这篇关于协议缓冲区:如何导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!