Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf error when compiling Java runtime library

I'm trying to build the Java run time library for Protocol Buffers. I've got errors on both Windows and OS X by following the README instruction under the Java directory in the Protocol Buffers project (which is cloned from https://github.com/google/protobuf).

The following error occured when I ran mvn test in the protobuf/java directory.

Error from OS X

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.8:run (generate-sources) on project protobuf-java: An Ant BuildException has occured: The following error occurred while executing this line:
[ERROR] /Users/wangsa/Work/ProtoBuffer/protobuf/java/core/generate-sources-build.xml:4: Execute failed: java.io.IOException: Cannot run program "/Users/wangsa/Work/ProtoBuffer/protobuf/java/core/../../src/protoc" (in directory "/Users/wangsa/Work/ProtoBuffer/protobuf/java/core"): error=2, No such file or directory

Error from Windows

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.google.protobuf:protobuf-java:bundle:2.6.1
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 57, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-surefire-plugin is missing. @ line 64, column 15
[WARNING] 'build.plugins.plugin.version' for org.apache.felix:maven-bundle-plugin is missing. @ line 143, column 15
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Protocol Buffer Java API 2.6.1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-antrun-plugin:1.3:run (generate-sources) @ protobuf-java ---
[INFO] Executing tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.030 s
[INFO] Finished at: 2016-06-07T10:03:48+12:00
[INFO] Final Memory: 11M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (generate-sources) on project protobuf-java: An Ant BuildException has occured: Execute failed: java.io.IOException: Cannot run program "..\src\protoc": CreateProcess error=2, The system cannot find the file specified -> [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

More details

  • Maven is properly installed (version 3.3.9)
  • Java JDK is properly installed (version 1.7 for OS X and 1.8 for Windows)
  • Protobuf is properly installed. I'm able to convert .proto file to .java file using the protoc command.
  • The version of protobuf is 2.6.1 for both the installed binary and the Java package I'm trying to build.

Can anyone see what might gone wrong?

Edit: Doing this build process is quite new to me, I assume if this process is done successfully, I will get a .jar file which I can include in my android program in order to use protobuf's methods generated from my proto file to serialise data and send over TCP, which is my end goal.

like image 256
shshchch88 Avatar asked Jan 05 '23 23:01

shshchch88


2 Answers

Finally got it working with the following changes:

Change 1: I changed to use the java source from https://github.com/google/protobuf/releases/tag/v2.6.1 instead of https://github.com/google/protobuf/tree/v2.6.1/java

Change 2: for the Windows machine I need to copy protoc.exe to the src folder that's located in the parent folder of the java folder. Previously I copied protoc.exe into the src inside the java folder which didn't work.

After that I ran mvn test in the java folder, everything worked. I was able to generate the .jar file using mvn install and then mvn package based on the README file.

Note: I don't understand why the code from protobuf/tree/v2.6.1 didn't work, but because on github, the build status also says failing (as of 7th June), so I assume that's why.

like image 90
shshchch88 Avatar answered Jan 14 '23 10:01

shshchch88


I faced the same issue. Made the following changes to get it working:

  1. Download the binary from the following link - same version as the one you are trying to compile (I used 3.2.0): https://repo1.maven.org/maven2/com/google/protobuf/protoc/

  2. Rename the executable from protoc-3.2.0-windows-x86_64.exe to protoc.exe

  3. run the mvn test from ..\protocol_buf\protobuf-3.2.0\java folder

like image 34
SKA Avatar answered Jan 14 '23 12:01

SKA