Using SnakeYaml under OSGi?

Does SnakeYaml work under OSGi? I changed the MANIFEST so that it expanded correctly, but an attempt to load a document into the JavaBean object structure fails with the exceptions "Class not found".

Thank.

+3
source share
2 answers

Sometimes it's as simple as adding manifest headers to make the jar game enjoyable in the OSGi sandbox. Sometimes banks / libraries do "naughty" things in the context of OSGi. The golden rule is to not use "Class.forName ()" because OSGi uses class loaders, otherwise it works fine in a single class loader environment. I pulled down the source in SnakeYaml and they are loader based beans using Class.forName.

, CustomClassLoaderConstructor, , , Yaml. . , Yaml, , - , , . , , OSGi.

. .

+8

, , snakeyaml osgi. MANIFEST.MF.

CustomClassLoaderConstructor :

import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor;

CustomClassLoaderConstructor constructor = new CustomClassLoaderConstructor(this.getClass().getClassLoader());
Config config = new Yaml(constructor).loadAs(in, Config.class);

, org.yaml.snakeyaml; bundle-version = "1.25.0"

0

Source: https://habr.com/ru/post/1790854/


All Articles