Getting java.lang.NoSuchFieldError: VALUE in RamlV

2019-05-21 06:44发布

问题:

I want to create a RAML validator that will get the RAML URLs resturn validation results. For that Im using raml-java-parser. As per its readme file I try to execute below line of code:

String sourceUrl = "http://api.apihub.com/onpositive/api/espn-raml-api/espn.raml";
List<ValidationResult> results = RamlValidationService.createDefault().validate(sourceUrl);

And get below error message:

java.lang.NoSuchFieldError: VALUE

Why I'm getting this error? Before that I got some class not found exceptions therefore I have applied below jar libraries manually.

> juniversalchardet_1.0.3_1.0.0.jar 
> raml_parser_0.8.11_1.0.0.jar
> rhino_1.7R4_1.0.0.jar 
> snakeyaml-1.16.jar
> jackson_databind_2.4.4_1.0.0.jar

I have tried below stuff as well. inputStream is the RAML content that I parsed through ByteArrayInputStream. But this is not a invalid RAML therefore I might doing something wrong.

回答1:

Never seen this error. I suspect you may still miss dependencies.

Indeed, the Java RAML parser has more dependencies than these few JARs you've manually added. And the dependencies you see in the pom are just the tip of the iceberg, there are tons of transitive dependencies as well.

So: use a proper dependency manager (like Maven) for your project. It will take care of bringing all the dependencies (direct and transitive) for you. Besides, unless this is a toy project, you will need a proper build tool anyway.