Adam Miller
Adam Miller

Reputation: 1783

Getting compile errors on protobuf generated java file - how to compile?

Title says it all;

"mvn compile" produces tons of errors, here's the first:

[ERROR] $HOME/workspace/JavaExamplePBServiceCall/src/main/java/example/ServicecallPiqi.java:[13,23] error: ';' expected

manual compilation produces 100 errors, here is the first:

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

Beginning of 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 

Here's my 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>

How do I get it to compile?

Upvotes: 2

Views: 8030

Answers (1)

Petr Janeček
Petr Janeček

Reputation: 38424

The Parser classes have been added only after version 2.5.0, but you're declaring dependency on protobuf v2.4.1.

You're probably compiling your .proto files with a later version of the compiler than what are the runtime classes you're adding to your POM file.

Update your dependency / downgrade your protoc compiler and everything will work just fine.

Upvotes: 5

Related Questions