当前位置: 首页 > 知识库问答 >
问题:

编译Java运行时库时出现Protobuf错误

杜焕
2023-03-14

我正在尝试为协议缓冲区构建Java运行时库。我在Windows和OS X上都犯了错误,因为我遵循了Protocol Buffers项目(从中克隆而来)中Java目录下的自述指令https://github.com/google/protobuf).

当我在protobuf/java目录下运行mvn测试时,出现了以下错误。

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

更多细节

  • Maven安装正确(3.3.9版)

有人能看出哪里出了问题吗?

编辑:做这个构建过程对我来说是相当新的,我假设如果这个过程成功完成,我会得到一个. jar文件,我可以将其包含在我的android程序中,以便使用从我的proto文件生成的Probuf方法来序列化数据并通过TCP发送,这是我的最终目标。


共有3个答案

高墨一
2023-03-14

我的项目中也有同样的问题,要解决这个问题,请在PATH环境变量中添加protocbin目录。

有时,即使在重启之后,eclipse也不会选择添加的路径,如果发生这种情况,只需删除。元数据工作区中的目录,它将工作。

现代操作系统可以立即识别环境变量的变化,但eclipse需要意识到这一点,它在大多数情况下都是在首次加载后从缓存中读取。

常英资
2023-03-14

我也面临同样的问题。进行了以下更改以使其正常工作:

>

从protoc-3.2.0-windows-x86_64重命名可执行文件。从exe到protoc。exe

从…运行mvn测试。。\protocol_buf\protobuf-3.2.0\java文件夹

蒙才
2023-03-14

最终通过以下更改使其工作:

更改1:我更改为使用来自的java源代码https://github.com/google/protobuf/releases/tag/v2.6.1而不是https://github.com/google/protobuf/tree/v2.6.1/java

改变2:对于Windows机器,我需要复制protoc。exe到位于java文件夹父文件夹中的src文件夹。之前我复制了protoc。exe进入java文件夹中的src,该文件夹不起作用。

之后,我在java文件夹中运行了mvn测试,一切正常。我能够生成。jar文件使用mvn安装,然后根据自述文件使用mvn包

注意:我不明白为什么protobuf/tree/v2中的代码会被删除。6.1不起作用,但因为在github上,构建状态也表示失败(截至6月7日),所以我认为这就是原因。

 类似资料:
  • C:\Users\SAYAN\Desktop\block-ch\project\khs-blockchain-java-example-master\src\main\java\simple\chain\Block.java:[51,29] 错误:-source 1.5 不支持 lambda 表达式 我已经安装了jdk 1.8。我仍然收到这个错误。需要帮助!!!

  • 问题内容: 我正在尝试使用JavaMail API发送电子邮件。我从自解压二进制文件在我的主目录中安装了jdk 1.5。我正在使用Ubintu 9.10 我使用下一条命令编译程序: 〜/ jdk1.5.0_22 / bin / javac -classpath〜/ jdk1.5.0_22 / jre / lib / javamail-1.4.3 / mail.jar:〜/ jdk1.5.0_22

  • 问题内容: 当以下Java代码在eclipse中执行时,它会提供正确的输出(即打印“ Class B”),但是根据Java规范,该代码无法编译(因为超类构造函数需要一个参数,并且构造函数由B类的编译器包括对超类no arg构造函数的调用(未定义),并且当尝试在命令行中使用javac命令编译文件时,它仅编译超类(即A类),并因以下编译而失败错误: 以下是java文件的内容: 有人可以解释eclips

  • 问题内容: 在Eclipse中运行Ant构建时,出现以下错误消息,并且Ant构建失败。 错误消息: 运行javac.exe编译器时出错 停止构建的行: 有人遇到过类似的问题吗?还是有人知道这是怎么回事? 系统信息:Eclipse Helio,JDK 1.5 问题答案: 我有同样的问题,问题是,在Eclipse中,java.home是指JRE而不是JDK。我进行了更改,构建成功。您可以执行以下操作将

  • 问题内容: 专业人士使用这两种方式的缺点是什么? 我实际上在Netbeans的“项目属性”>“ Java应用程序的库”中看到了它。我们有两个选项卡,一个用于编译时间库和运行时库,看起来我们可以将一个库添加到彼此独立的一个库中 问题答案: “库属性”对话框的用户界面和术语非常混乱。 该对话框上的“帮助”按钮将为您提供一些信息。 编译时库列表可以是运行时库列表的子集。 考虑这种情况… 您具有从库“ w

  • 问题内容: 根据运行时错误消息,异常发生在下一行; 是具有构造函数和重载构造函数的类,其中包含有关数据库中每种病毒的特定信息,例如; 字符串vName 字符串vDefinition 重载 具有标记化定义的数组(以xLength组分隔) 具有LCS令牌的阵列 有等级浮动 类型的是.iterator(),如下所示: 是和ArrayList类型,用于存储病毒对象 (此时为名称和定义), 以便以后使用。