Hello
This post describes how to integrate json-schema-validator 2.2.5 in an OSGi container.
json-schema-validator home page redirect to the binary download site to get OSGi ready library. But with this last one I was unable to make json-schema-validator working... I got an unsatisfied package jackson-databind.
So I decide to integrate by hand json-schema-validator and related dependencies. 14 jar to get and check (see into the MANIFEST.MF the "Export-Packages" directive..)
Here is the way :
- use json-schema-validator in your Eclipse Java project by adding the pom dependency.
- make a sample unit test working (see example package of the json-schema-validator project).
- open your project "pom.xml" file using eclipse to know the current dependency tree (view called "Dependency Hierarchy").
After getting one-by-one each mandatory dependendency of the json validator, here is the final list I get :
- btf-1.2.jar
- jackson-annotations-2.4.1.jar
- jackson-core-2.4.1.1.jar
- msg-simple-1.1.jar
- jackson-databind-2.4.1.3.jar
- guava-16.0.1.jar
- uri-template-0.9.jar
- jackson-coreutils-1.8.jar
- rhino-1.7R4.jar
- libphonenumber-6.0.jar
- mailapi-1.4.3.jar
- jopt-simple-4.6.jar
- joda-time-2.3.jar
- json-schema-core-1.2.4.jar
- json-schema-validator-2.2.5.jar
You can get each jar from a given maven repository; example joda-time-2.3.jar.
For each jar, I have to check the OSGi Export package directive. Here is the way to do that :
- open the jar file using zip tool (ex. 7zip)
- edit the file "META-INF/MANIFEST.MF"
- check that the file contains an Export package directive like the following example for yoda time :
Export-Package: org.joda.time;version=2.3,org.joda.time.base;version=2 .3,org.joda.time.chrono;version=2.3,org.joda.time.convert;version=2.3 ,org.joda.time.field;version=2.3,org.joda.time.format;version=2.3,org .joda.time.tz;version=2.3
- rhino-1.7R4.jar
- get an updated version here
Export-Package: org.mozilla.javascript;version="1.7"
Export-Package: com.google.i18n.phonenumbers;version="6.0"
Export-Package: joptsimple;version="4.6"
jopt-simple-4.8-SNAPSHOT.jar
After all these steps, when I want to validate a json content with a schema, I got an error while loading meta-schema "/draftv4/schema" (problem of class loading).
Until now, I have not figured out how to fix it.
java.lang.ExceptionInInitializerError at com.github.fge.jsonschema.SchemaVersion.This file is present into "json-schema-core-1.2.4.jar" but not loaded as resource by OSGi container...(SchemaVersion.java:65) at com.github.fge.jsonschema.SchemaVersion. (SchemaVersion.java:44) at com.github.fge.jsonschema.core.load.configuration.LoadingConfigurationBuilder. (LoadingConfigurationBuilder.java: 17) at com.github.fge.jsonschema.core.load.configuration.LoadingConfiguration.byDefault(LoadingConfiguration.java:151) (...) Caused by: java.io.IOException: resource /draftv4/schema not found at com.github.fge.jackson.JsonLoader.fromResource(JsonLoader.java:91) at com.github.fge.jsonschema.SchemaVersion. (SchemaVersion.java:63)
Following this error, I just open an issue json-schema-validator issue #111.
As workaround, with the help of Gábor Bakos and as first draft, I just push a "OSGi'fyed" version of the "json-schema-validator" here : github.com boly38 json-schema-validator-bundle.
Of course any feedbacks are welcome
Aucun commentaire:
Enregistrer un commentaire