如何编译google-fhir proto文件 [英] How to compile google-fhir proto files
问题描述
查看google-fhir的自述文件,它说要运行 bazel build
,这有效,但是没有编译任何协议文件。
Looking at the readme for google-fhir it says to run bazel build
, which works, however none of the protocol files have been compiled.
运行 protoc --proto_path =。 --java_out =。 proto / stu3 / resources.proto
返回一堆关于未找到其他protos的错误。这会向后移动,直到'descriptor.proto'不是文件夹中的原型。该目录中的所有协议文件都不会手动编译成java文件。
Running protoc --proto_path=. --java_out=. proto/stu3/resources.proto
returns a bunch of error about other protos not being found. This goes backwards until 'descriptor.proto' which is not a proto in the folder. None of the protocol files in that directory will manually compile into java files.
*另一方面,我能够从其他来源获取其他示例protos并成功编译。
*On another note, I was able to take other example protos from other sources and compile those successfully.
更新
运行命令 protoc - 来自google-fhir基目录的-proto_path = proto / stu3 / --java_out = target proto / stu3 / resources.proto
返回以下输出:
Running the command protoc --proto_path=proto/stu3/ --java_out=target proto/stu3/resources.proto
from the google-fhir base directory returns the following output:
~/fhir-master$ protoc --proto_path=proto/stu3/ --java_out=target proto/stu3/resources.proto
proto/stu3/annotations.proto: File not found.
proto/stu3/codes.proto: File not found.
proto/stu3/datatypes.proto: File not found.
resources.proto: Import "proto/stu3/annotations.proto" was not found or had errors.
resources.proto: Import "proto/stu3/codes.proto" was not found or had errors.
resources.proto: Import "proto/stu3/datatypes.proto" was not found or had errors.
resources.proto:84:5: "String" is not defined.
resources.proto:87:14: "Extension" is not defined.
resources.proto:90:14: "Extension" is not defined.
resources.proto:94:5: "Reference" is not defined.
resources.proto:97:5: "PositiveInt" is not defined.
...
...
这些文件肯定位于同一个原型目录中。
Those files are definitely located in the same proto directory.
更新2
嗯,这绝对不是开箱即用的。移动文件,我能够用一堆Java文件生成目标文件夹。但是,尝试编译它们时,我会收到不存在的文件的错误:
Well, this definitely doesn't work right out of the box. Moving the files around, I was able to generate the target folder with a bunch of Java files. However, trying to compile them, I get errors for files that don't exist:
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30950: error: cannot find symbol
public com.google.fhir.stu3.proto.CodeableConceptOrBuilder getJurisdictionOrBuilder(
^
symbol: class CodeableConceptOrBuilder
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30956: error: cannot find symbol
private java.util.List<com.google.fhir.stu3.proto.CodeableConcept> topic_;
^
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30964: error: cannot find symbol
public java.util.List<com.google.fhir.stu3.proto.CodeableConcept> getTopicList() {
^
symbol: class CodeableConcept
location: package com.google.fhir.stu3.proto
./PlanDefinition.java:30974: error: cannot find symbol
public java.util.List<? extends com.google.fhir.stu3.proto.CodeableConceptOrBuilder>
.... ^
100 errors.
!另外,我在这里看不到这些文件: https://github.com/google/protobuf/tree/master/java/core/src/main/java/com/google/protobuf
! Also, I don't see these file here: https://github.com/google/protobuf/tree/master/java/core/src/main/java/com/google/protobuf
推荐答案
看起来你的编译命令格式不正确:
--proto_path =这是proto的路径
--java_out =这是您的类将被编译的文件夹
it looks like your command for compilation is not well formatted: --proto_path= This is the path to your proto --java_out= This is the folder where your class will be compiled
您的论点是:proto / stu3 / resources.proto,因此我推断您的文件位于proto / stu3中。
Your arguement is: proto/stu3/resources.proto, so I deduce that your files are located in proto/stu3.
你可以尝试这个命令,告诉我们它是否适合你:
Could you try this command and let us know if it worked for you:
protoc --proto_path=proto/stu3/ --java_out=target proto/stu3/resources.proto
如果你的proto描述符已经完成,你应该没有编译错误,你的结果应该在target文件夹中。
If your proto descriptor are complete, you should have no compilation error, and your result should be in the folder "target".
编辑:
看在你的最新编辑中,我会说你应该将resources.proto移动到你的基目录并运行以下命令:
protoc --proto_path =。 --java_out = target resources.proto
由于导入的路径已在导入中编码。
这有点难以帮助,因为我们无法访问您的整个proto描述符。如果你从在线回购中获取它,如果你可以分享它会有所帮助。
As the path to your import is coded in your import. This is a bit difficult to help, as we don't have access to your entire proto descriptor. If you took it from an online repo, it would help if you could share it.
这篇关于如何编译google-fhir proto文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!