我正在尝试为Protocol Buffers构建Java运行时库。通过遵循Protocol Buffers项目(从https://github.com/google/protobuf克隆)中的Java目录下的README指令,我在Windows和OS X上都出现了错误。
我在protobuf / java目录中运行mvn test
时发生以下错误。
来自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
来自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
更多详情
protoc
命令将.proto文件转换为.java文件。任何人都可以看到可能出现的问题吗?
编辑: 做这个构建过程对我来说是一个全新的过程,我假设如果这个过程成功完成,我会得到一个.jar文件,我可以将其包含在我的android程序中,以便使用从我的proto文件生成的protobuf方法来序列化数据并通过TCP发送,这是我的最终目标。
答案 0 :(得分:3)
最后让它使用了以下更改:
更改1:我更改为使用https://github.com/google/protobuf/releases/tag/v2.6.1中的java源而不是https://github.com/google/protobuf/tree/v2.6.1/java
对于我需要将protoc.exe复制到位于java文件夹的父文件夹中的src
文件夹的Windows机器, 更改2:。以前我将protoc.exe复制到了java文件夹中的src
,但是没有用。
之后我在java文件夹中运行mvn test
,一切正常。我能够使用mvn install
生成.jar文件,然后基于README文件生成mvn package
。
注意:我不明白为什么protobuf / tree / v2.6.1中的代码不起作用,但因为在github上,构建状态也表示失败(截至6月7日),所以我认为这就是原因。
答案 1 :(得分:1)
在我的项目中遇到同样的问题,要解决此问题,请在protoc
环境变量中添加PATH
bin目录。
有时eclipse甚至在重新启动后也不会选择添加的路径,如果发生这种情况只是删除工作区中的.metadata
目录,它就会起作用。
现代操作系统会立即识别环境变量的变化,但是eclipse需要意识到这一点,它会在大部分时间首次加载后从缓存中读取。
答案 2 :(得分:1)
我遇到了同样的问题。进行了以下更改以使其正常工作:
从以下链接下载二进制文件 - 与版本相同 一个你想编译(我使用3.2.0): https://repo1.maven.org/maven2/com/google/protobuf/protoc/
将可执行文件从protoc-3.2.0-windows-x86_64.exe重命名为protoc.exe
从.. \ protocol_buf \ protobuf-3.2.0 \ java文件夹运行mvn测试
答案 3 :(得分:0)
当我也尝试“ MVN安装”时,我遇到了这个问题。
我遇到此错误:协议执行失败,因为:null:IllegalArgumentException
要解决此问题,请执行以下操作:
mvn -Dprotoc.dir=<your protoc.exe bin directory> install
成功了!