Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protocol Buffer: How to import?

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

like image 407
Echo Avatar asked Nov 27 '25 13:11

Echo


1 Answers

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

like image 94
laher Avatar answered Nov 29 '25 02:11

laher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!