1

这与此处的错误相同:Getting java.lang.NoSuchFieldError: VALUE in RamlValidationService

但是,在那种情况下,问题不在于将 Maven 用于 deps,但我正在这样做。

我的简单 RAML 文件:

/echo:
    /{str}:
        uriParameters:
            str:
                type: string
        get:
            displayName: Used to retrieve a specific page
            responses:
                200:
                    displayName: Page returned successfully
                404:
                    displayName: Page not found

我的简单 Java 用法:

File apiDir = new File("api");

        File[] directoryListing = apiDir.listFiles();
        if (directoryListing != null) {
            for (File child : directoryListing) {
                RamlDocumentBuilder rdb = new RamlDocumentBuilder();
                System.out.println("________ child.getAbsolutePath(): "
                        + child.getAbsolutePath());
                if (child != null) {
                    try {
                        Raml raml = rdb.build(new FileReader(child));
                    } catch (FileNotFoundException fnfe){
                        throw new RuntimeException("Problem with raml file: ", fnfe);
                    }
                } else {
                    System.out.println("Ignoring file: " + child);
                }
            }
        } else {
            throw new RuntimeException("api directory is not a directory.");
        }

我的简单 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>my.group</groupId>
    <artifactId>my-project</artifactId>
    <version>0.0.1</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <compilerVersion>1.8</compilerVersion>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>io.fastjson</groupId>
            <artifactId>boon</artifactId>
            <version>0.33</version>
        </dependency>
        <dependency>
            <groupId>com.squareup</groupId>
            <artifactId>javapoet</artifactId>
            <version>1.5.1</version>
        </dependency>
        <dependency>
            <groupId>org.raml</groupId>
            <artifactId>raml-parser</artifactId>
            <version>0.8.11</version>
        </dependency>
    </dependencies>
</project>

这是有趣的错误:

Exception in thread "main" java.lang.NoSuchFieldError: VALUE
    at org.raml.parser.utils.NodeUtils.<clinit>(NodeUtils.java:34)
    at org.raml.parser.visitor.NodeVisitor.resolveTag(NodeVisitor.java:164)
    at org.raml.parser.visitor.NodeVisitor.doVisitMappingNode(NodeVisitor.java:139)
    at org.raml.parser.visitor.NodeVisitor.visitDocument(NodeVisitor.java:209)
    at org.raml.parser.visitor.YamlDocumentBuilder.build(YamlDocumentBuilder.java:90)
    at org.raml.parser.visitor.YamlDocumentBuilder.build(YamlDocumentBuilder.java:113)
    at my.group.App.main(App.java:27)

编辑 1:如果我直接使用 SnakeYAML,一切都很好。

4

0 回答 0