Unable to install protoc on Windows

6k views Asked by At

I'm finding problems with building protoc jar which is meant for generating java class files from proto files. I'd really appreciate any kind of direction or help in setting up the project to a level where I can generate java class files from .proto files

I have imported the following projects from protobuf git repo, but have been unable to find the protoc.exe file in the project directories.

enter image description here

The projects themselves complain about not being able to reference certain classes.enter image description here

When I tried compiling and building the protobuf-parent project with maven,I get errors as show below

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

There are 1 answers

0
Whome On BEST ANSWER

I recommend you to use a precompiled protoc.exe binary file on Windows. Download protoc-x.x.x-win32.zip and protoc-x.x.x-java.zip packages

Unzip files you should get a folders like this (listing only few key files):

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\*

Compile java project using Maven, see this helper bat script:

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

You should find jar files in the following folders, these are the files you embed to your project when using MyStructureProto.java or other protobuf objects (bytes to object, object to bytes).

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

Use protoc.exe to create java implementation from .proto template descriptor:

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