Protocol Buffer: How to import?

故事扮演 提交于 2019-12-22 17:42:29

问题


I have 2 .proto files :

First file:

package com.test.model;

message ProtoModel  {
    required CustomObj custom=1;
}

Second file:

package com.test.model;

message CustomObj {
    required string smth=1;
}

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 !!


回答1:


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.

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

and your import statement would be import "src/main/resources/firstFile.proto"

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



来源:https://stackoverflow.com/questions/7947277/protocol-buffer-how-to-import

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!