【问题标题】:Maven cannot find symbol, but independent build worksMaven找不到符号,但独立构建工作
【发布时间】:2013-09-05 14:16:48
【问题描述】:

我正在编写 Pig UDF,并尝试使用 Maven 将其编译成 jar。该代码在 Eclipse 中注册为正常,但是当我在 Maven 中构建它时,出现找不到符号错误,如下所示。我检查了 openReader 方法的方法签名,它与我传递的类匹配,所以我不确定 Maven 编译出了什么问题。

依赖片段:

<dependency>
    <groupId>org.apache.hadoop</groupId>
    <artifactId>hadoop-core</artifactId>
    <version>${hadoop.version}</version>
    <exclusions>
        <exclusion>
            <groupId>hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
        </exclusion>
        <exclusion>
            <groupId>net.sf.kosmosfs</groupId>
            <artifactId>kfs</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.eclipse.jdt</groupId>
            <artifactId>core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>net.java.dev.jets3t</groupId>
            <artifactId>jets3t</artifactId>
        </exclusion>
        <exclusion>
            <groupId>oro</groupId>
            <artifactId>oro</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro-mapred</artifactId>
    <version>1.7.5</version>
</dependency>
<dependency>
    <groupId>org.apache.avro</groupId>
    <artifactId>avro</artifactId>
    <version>1.7.5</version>
</dependency>

代码片段:

import org.apache.avro.file.DataFileReader;
import org.apache.avro.file.FileReader;
import org.apache.avro.file.SeekableInput;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
import org.apache.avro.mapred.FsInput;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;

protected String getLastRecord(String location) throws IOException {
  Path path = new Path(location);
  Configuration config = new Configuration();
  SeekableInput input = new FsInput(path, config);
  DatumReader<GenericRecord> reader = new GenericDatumReader<GenericRecord>();
  FileReader<GenericRecord> fileReader = DataFileReader.openReader(input, reader);
  Iterator<GenericRecord> itr = fileReader.iterator(); 

  long initialPosition = input.tell();
  itr.next();
  long newPosition = input.tell();

  input.seek(input.length() - (initialPosition - newPosition));
  return itr.next().get("id").toString();
};

错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project newscred-recsys-udfs: Compilation failure
[ERROR] /Users/andrew/Code/recommender/hadoop/newscred_recsys/udfs/java/src/main/java/com/mortardata/newscred/recsys/SqoopAvroLoader.java:[104,64] cannot find symbol
[ERROR] symbol:   method openReader(org.apache.avro.file.SeekableInput,org.apache.avro.io.DatumReader<org.apache.avro.generic.GenericRecord>)
[ERROR] location: class org.apache.avro.file.DataFileReader
[ERROR] -> [Help 1]

【问题讨论】:

    标签: java eclipse maven hadoop avro


    【解决方案1】:

    应该清理项目。项目 -> 清理

    【讨论】:

      【解决方案2】:

      显然,org.apache.avro 的 jar 与从 Apache 网站分发的 jar 的方法集不同,导致不匹配。

      【讨论】:

      • 似乎很奇怪...您是否尝试在 Eclipse 中使用本地 maven 存储库中的 avro jar ?
      • 这就是我解决问题的方法。在我使用开发期间从 apache 站点下载的那个之前。但是我去更新maven文件的时候,遇到了这个问题。
      猜你喜欢
      • 2021-04-17
      • 2019-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 2014-09-05
      • 1970-01-01
      相关资源
      最近更新 更多