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