2017-08-31 116 views
0

我正在發現構建protoc jar的問題,它是用於從proto文件生成java類文件的。我真的很感謝任何一種方向或幫助建立項目的水平,我可以從.proto文件生成Java類文件無法在Windows上安裝protoc

我從protobuf git repo導入了以下項目,但一直無法找到項目目錄中的protoc.exe文件。

enter image description here

自己抱怨不能夠引用某些類的項目。 enter image description here

當我試圖編譯和使用Maven構建的protobuf-父項目,我得到的錯誤,如下面顯示

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

,我建議你在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項目,請參閱本幫助蝙蝠腳本:

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