Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two proto files inside single directory and I am looking for a way to generate classes from those files in a single command. It seems that this can be accomplished with the --proto_path argument. As per the documentation:

You must provide one or more .proto files as input. Multiple .proto files can be specified at once. Although the files are named relative to the current directory, each file must reside in one of the IMPORT_PATHs [specified by the --proto_path argument] so that the compiler can determine its canonical name.

C:shekharproto_trial>dir
 Volume in drive C is C

 Directory of C:shekharproto_trial

07/25/2014  12:16 PM    <DIR>          .
07/25/2014  12:16 PM    <DIR>          ..
07/25/2014  12:16 PM    <DIR>          java_op
07/25/2014  12:16 PM               230 map.proto
07/23/2014  04:24 PM               161 message.proto
07/25/2014  12:17 PM             1,228 response.proto
               3 File(s)          1,619 bytes
               3 Dir(s)  50,259,398,656 bytes free

I used --proto_path argument as shown below

C:shekharproto_trial>protoc 
                       --proto_path=C:shekharproto_trial 
                       --java_out=C:shekharproto_trialjava_op 
                       *.proto

but I am getting following error

message.proto: File does not reside within any path specified using --proto_path (or -I). 
You must specify a --proto_path which encompasses this file. 
Note that the proto_path must be an exact prefix of the .proto file names -- protoc is unable to figure out when two paths (e.g. absolute and relative) are equivalent (it's harder than you think).

Please suggest some way to compile all the proto files together in single shot.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
659 views
Welcome To Ask or Share your Answers For Others

1 Answer

The problem is that you are specifying --proto_path as an absolute path but your proto files as relative paths. You can either drop the --proto_path argument (it defaults to the current directory anyway), or you can do:

protoc --proto_path=C:shekharproto_trial
       --java_out=C:shekharproto_trialjava_op
       C:shekharproto_trial*.proto

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...