无法在Windows上安装protoc

时间:2017-08-31 04:03:22

标签: maven protocol-buffers protobuf-net proto

我发现构建protoc jar的问题是为了从proto文件生成java类文件。我非常感谢任何方向或帮助将项目设置到我可以从.proto文件生成java类文件的级别

我从protobuf git repo导入了以下项目,但无法在项目目录中找到protoc.exe文件。

enter image description here

项目本身抱怨无法引用某些课程。enter image description here

当我尝试使用maven编译和构建protobuf-parent项目时,我收到错误,如下所示

main:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Protocol Buffers [Parent] .......................... SUCCESS [  0.173 s]
[INFO] Protocol Buffers [Core] ............................ FAILURE [  0.736 s]
[INFO] Protocol Buffers [Util] ............................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.347 s
[INFO] Finished at: 2017-08-30T20:52:49-07:00
[INFO] Final Memory: 16M/220M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (compile-protoc) on project protobuf-java: An Ant BuildException has occured: C:\scratch1\protobuf\protobuf-master\java\core\src\main\proto does not exist.
[ERROR] around Ant part ...<pathconvert property="proto.files" pathsep=" " refid="proto.path"/>... @ 10:71 in C:\scratch1\protobuf\protobuf-master\java\core\target\antrun\build-main.xml
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

1 个答案:

答案 0 :(得分:1)

我建议您在Windows上使用预编译的protoc.exe二进制文件。 Download protoc-x.x.x-win32.zip and protoc-x.x.x-java.zip packages

解压缩文件你应该得到这样的文件夹(只列出几个关键文件):

C:\projects\protoc\protoc-x.x.x-win32\bin\protoc.exe
C:\projects\protoc\protoc-x.x.x\protobuf.pc.in
C:\projects\protoc\protoc-x.x.x\java\pom.xml
C:\projects\protoc\protoc-x.x.x\java\core\*
C:\projects\protoc\protoc-x.x.x\java\util\*

使用Maven编译java项目,请参阅此帮助程序bat脚本:

cd C:\projects\protoc\protobuf-x.x.x\java
set JAVA_HOME=c:\program files\Java\jdk1.7.0_75
"c:\apps\apache-maven\bin\mvn.cmd" "-Dprotobuf.source.dir=C:\projects\protoc\protoc-x.x.x-win32\bin" package

您应该在以下文件夹中找到jar文件,这些是使用MyStructureProto.java或其他protobuf对象(字节到对象,对象到字节)时嵌入到项目中的文件。

C:\projects\protoc\protoc-x.x.x\java\core\target\protobuf-java-3.3.0.jar
C:\projects\protoc\protoc-x.x.x\java\util\target\protobuf-java-util-3.3.0.jar

使用protoc.exe从.proto模板描述符创建java实现:

C:\projects\protoc\protoc-x.x.x-win32\bin\protoc.exe --java_out=. MyStructureProto.proto