shshchch88
shshchch88

Reputation: 453

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

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.

Upvotes: 6

Views: 28010

Answers (4)

J.Doe
J.Doe

Reputation: 189

I had this issue come when I tried to "mvn install" as well.

I was getting this error: protoc failed to execute because: null: IllegalArgumentException

To fix I did the following:

mvn -Dprotoc.dir=<your protoc.exe bin directory> install

and it worked!!

Upvotes: 2

SKA
SKA

Reputation: 67

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

Upvotes: 3

shshchch88
shshchch88

Reputation: 453

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.

Upvotes: 5

Saravana
Saravana

Reputation: 12817

Had the same issue in my project, to fix this, add protoc bin directory in the PATH environment variable.

Sometimes eclipse won't pick the path added even after restart, if this happened just delete .metadata directory in workspace, it will work.

Modern OS recognizes the environment variable changes instantly but eclipse needs to aware of this, it reads from cache after first load most of the time.

Upvotes: 1

Related Questions