6

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.

4
  • The build process can not find the protoc program. This program converts proto definitions to java programs. Have you built the proto buffer for C yet. Where is the protoc programs Also for Windows you should be able to download protoc program if need be. Commented Jun 5, 2016 at 4:49
  • 1
    do you copy your protoc to ../src folder as "You will need to place the protoc executable in ../src. (If you built it yourself, it should already be there.)" Commented Jun 5, 2016 at 5:10
  • No, I have not explicitly built the proto buffer for C, because there is nowhere mentioned to do that. You mean to build in C++ right? Commented Jun 5, 2016 at 5:13
  • @andy Hi Andy, I have copied the protoc file into the src directory. It was not in there previously (maybe it indicates something?) But I still got the same error. Commented Jun 5, 2016 at 5:28

4 Answers 4

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

for me this help I need to copy protoc.exe to the src folder that's located in the parent folder of the java folder. the same for mac users: just copy protoc file from /usr/local/bin to /protobuf-x.x.x/src folder. than navigate to java folder and run command mvn package
3

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

1 Comment

you can also add protoc.exe path to environment variables to run the mvn test from anywhere.
2

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!!

1 Comment

Are the greater then & less then signs part of the command?
1

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.

1 Comment

Hi, the folder containing the protoc executable is already in the PATH if that's what you mean by the protoc bin directory. The error still occurs. I assume use of eclipse will come after I successfully build this - I can't put the java files straight into eclipse right. Please do correct me if I'm wrong. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.