在protobuf生成的java文件中获取编译错误 - 如何编译?

时间:2014-11-30 00:13:06

标签: java protocol-buffers javac

标题说明了一切;

“mvn compile”产生大量错误,这是第一个:

[ERROR] $ HOME / workspace / JavaExamplePBServiceCall / src / main / java / example / ServicecallPiqi.java:[13,23]错误:';'预期

手动编译产生100个错误,这是第一个:

javac -cp $ HOME / .m2 / repository / com / google / protobuf / protobuf-java / 2.4.1 / protobuf-java-2.4.1.jar ServicecallPiqi.java

ServicecallPiqi.java:535: error: cannot find symbol
    public static com.google.protobuf.Parser<params> PARSER =
                                     ^
  symbol:   class Parser
  location: package com.google.protobuf

ServicecallPiqi.java的开头:

package example;
// Generated by the protocol buffer compiler.  DO NOT EDIT!
// source: pb_piqi_out/servicecall.piqi.proto

public final class ServicecallPiqi {
  private ServicecallPiqi() {}
  public static void registerAllExtensions(
      com.google.protobuf.ExtensionRegistry registry) {
  }
  /**
   * Protobuf enum {@code cast_type}
   */
  public enum cast_type implements
//  ^^^^^^^^^^^^^ OFFENDING line 

这是我的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example</groupId>
  <artifactId>JavaExamplePBServiceCall</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>PBServiceCallExample</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.protobuf</groupId>
      <artifactId>protobuf-java</artifactId>
      <version>2.4.1</version>
    </dependency>
  </dependencies>
</project>

如何编译?

1 个答案:

答案 0 :(得分:5)

The Parser classes have been added only after version 2.5.0,但你宣布对protobuf v2.4.1的依赖。

您可能正在使用更高版本的编译器编译.proto文件,而不是您要添加到POM文件的运行时类。

更新你的依赖/降级你的protoc编译器,一切都会正常工作。