1

如果我直接从测试程序中引用SnakeYAML jar(见底部),一切正常。如果我在我的 Maven 创建的项目中,我会从我的单元测试中获得以下输出:

java.lang.NoSuchMethodError: java.util.LinkedList.push(Ljava/lang/Object;)V
    at org.yaml.snakeyaml.scanner.ScannerImpl.addIndent(ScannerImpl.java:482)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchBlockEntry(ScannerImpl.java:653)
    at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:268)
    at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:178)
    at org.yaml.snakeyaml.parser.ParserImpl$ParseImplicitDocumentStart.produce(ParserImpl.java:213)
    at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:172)
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143)
    at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:163)
    at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:66)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:60)
    at org.yaml.snakeyaml.Loader.load(Loader.java:35)
    at org.yaml.snakeyaml.Yaml.load(Yaml.java:134)

由于 Maven 在中央存储库中找不到 SnakeYAML,因此我手动将其安装到本地存储库中。万一这很重要,我在使用 SnakeYAML 0.9 和 Maven 2.0.9 的 Mac 上。

示例 YAML 文件

- 
    accountCode: foo
    accountId: 1
    email: foo@bar.com
    userId: 1

工作测试程序

import java.io.*;
import java.util.*;

import org.yaml.snakeyaml.Yaml;

/**
 * Testing SnakeYAML.
 *
 * @author Hank Gay
 */
public final class Foo {
    public static void main(final String[] args) throws Exception {
        final Yaml yaml = new Yaml();
        Reader reader = null;
        try {
            reader = new FileReader("/tmp/foo.yaml");
            System.out.println(yaml.load(reader));
        } catch (final FileNotFoundException fnfe) {
            System.err.println("We had a problem reading the YAML from the file because we couldn't find the file." + fnfe);
        } finally {
            if (null != reader) {
                try {
                    reader.close();
                } catch (final IOException ioe) {
                    System.err.println("We got the following exception trying to clean up the reader: " + ioe);
                }
            }
        }
    }
}
4

2 回答 2

3

似乎是 JDK 版本问题:在 Java 6LinkedList#push中引入。

在运行 Maven 之前尝试设置JAVA_HOME为正确的版本。

于 2009-01-14T15:23:54.057 回答
2

在 1.0rc1 版本中修复

所有 Java 6 依赖项都从 SnakeYAML 中删除。

于 2009-01-16T17:32:27.710 回答