繁体   English   中英

是否有人从本地Maven存储库成功使用SnakeYAML加载了YAML文件?

[英]Has anyone succesfully loaded a YAML file using SnakeYAML from a local Maven repo?

如果我直接从测试程序中引用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,因此我将其手动安装到本地存储库中。 如果很重要,我在Mac上使用SnakeYAML 0.9和Maven 2.0.9。

样本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);
                }
            }
        }
    }
}

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

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

在版本1.0rc1中已修复

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM