Hi,

the point is, that with Java11 API and implementation/s are separated.
But the API JAXBContext loads the implementation.

In OSGi this would mean, that the JAXB-API has to know the
implementation. This is not the case. As default, JAXB tries to load
from jaxb.properties in the package of your entities, or a system
property, or in OSGi using HK2 which tracks the Java ServiceLoader
information or the default implementation:
com.sun.xml.bind.v2.ContextFactory using the context class loader. This
will all fail, unless you provide a class-loader that knows the
implementation, best using import package.

Thats why the most approaches using exactly that, by importing the
either com.sun.xml.bind.v2 or for  Moxy org.eclipse.persistence.jaxb.
Then you can create you JAXBContext like this:

JAXBContext.newInstance(Bookstore.class.getPackageName(),
Bookstore.class.getClassLoader())

If you dont like that approach, you are best putting your jaxb
implementation and api on the classpath the framework is started with.

Using bndtools this is very easy using the runpath instruction:

-runpath: \
    jakarta.activation-api;version='[1.2.2,1.2.3)',\
    jakarta.xml.bind-api;version='[2.3.3,2.3.4)',\
    org.eclipse.persistence.core;version='[2.7.6,2.7.7)',\
    org.eclipse.persistence.moxy;version='[2.7.6,2.7.7)'

...

-runfw:
org.eclipse.osgi;version='[3.13.100.v20180827-1536,3.13.100.v20180827-1536]'
-runee: JavaSE-11
-runvm:
-Djavax.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.JAXBContextFactory

You are then fine with import-package declarations without
implementation details for the entities bundles as well as for the
bundle that creates the JAXBContext:

Import-Package
  javax.xml.bind                         {version=[2.3,3)}
  javax.xml.bind.annotation              {version=[2.3,3)}
  javax.xml.bind.annotation.adapters     {version=[2.3,3)}


In that case you can create you JAXBContext like this:

JAXBContext jc = JAXBContext.newInstance(Bookstore.class);

But I dont know how to put additional jars to the framework class path
when using the Equinox Launcher, like the RCP does.

There is a section for implicit dependencies in the target platform
editor, that seems not to save anything. Playing around with the
osgi.frameworkClassPath laucher property didn't succeed. Maybe you have
additionally define the packages via
org.osgi.framework.system.packages.extra.

Regards,

Mark


At some point you will reach

Am 01.08.20 um 14:53 schrieb Lars Vogel:
Thanks, Mark

Mark Hoffmann <mark.hoffm...@web.de <mailto:mark.hoffm...@web.de>>
schrieb am Fr., 31. Juli 2020, 20:49:

    Hi Lars,

    I will take a look into it over the weekend.

    Regards,
    Mark

    -------- Ursprüngliche Nachricht --------
    Von: Lars Vogel <lars.vo...@vogella.com
    <mailto:lars.vo...@vogella.com>>
    Datum: 31.07.20 13:49 (GMT+01:00)
    An: Equinox development mailing list <equinox-dev@eclipse.org
    <mailto:equinox-dev@eclipse.org>>
    Betreff: Re: [equinox-dev] JAXB with Java 11 in OSGi

    Hi Neil, Dmytro and Mark,

    I tried this but I'm still getting the ClassNotFound Exception.

    I uploaded a tiny example here:
    https://github.com/vogellacompany/eclipsercp-jaxb-java11

    In case you want to test, clone the repo, import the example into
    Eclipse and activate the jaxbtarget.target definition and start the
    application via the com.vogella.jaxb.product.

    Press the button called "Trigger JAXB"

    Results in ClassNotFoundException

    Caused by: java.lang.ClassNotFoundException:
    org.eclipse.persistence.jaxb.JAXBContextFactory at
    
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
    at
    
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at
    
org.eclipse.osgi.internal.framework.ContextFinder.loadClass(ContextFinder.java:147)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522) at
    javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:480) at
    javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:184) … 29
    more

    Best regards, Lars

    On Tue, Jul 28, 2020 at 3:07 PM Neil Bartlett
    <njbartl...@gmail.com <mailto:njbartl...@gmail.com>> wrote:
    >
    > Hi Lars,
    >
    > Dmytro is correct, the jaxb-api and javax.activation bundles are
    required to provide the JAXB API on Java 11. You will also need an
    implementation of the API... the org.eclipse.persistence.core and
    org.eclipse.persistence.moxy bundles from EclipseLink provide this.
    >
    > I have had JAXB working with RCP for some time on J11 but
    unfortunately cannot share the code because it is commercial.
    >
    > Neil
    >
    > On Tue, 28 Jul 2020 at 14:03, Dmytro Pishchukhin
    <dmytro.pishchuk...@gmail.com
    <mailto:dmytro.pishchuk...@gmail.com>> wrote:
    >>
    >> Hi Lars,
    >>
    >> Try to use 2 bundles to resolve JAXB packages:
    >> - jaxb-api (javax.xml.bind:jaxb-api:2.3.1)
    >> - javax.activation (com.sun.activation:javax.activation:1.2.0)
    >>
    >> On Tue, Jul 28, 2020 at 1:56 PM Lars Vogel
    <lars.vo...@vogella.com <mailto:lars.vo...@vogella.com>> wrote:
    >>>
    >>> Friends of OSGi,
    >>>
    >>> Is anyone aware of an example / description of how to use JAXB
    with
    >>> Java 11 in OSGI (Eclipse RCP)? If yes, please share it with me.
    >>>
    >>> The examples I found for Java 11 are not inside OSGi and fail
    for me.
    >>>
    >>> Best regards, Lars
    >>>
    >>>
    >>>
    >>> --
    >>> Eclipse Platform project co-lead
    >>> CEO vogella GmbH
    >>>
    >>> Haindaalwisch 17a, 22395 Hamburg
    >>> Amtsgericht Hamburg: HRB 127058
    >>> Geschäftsführer: Lars Vogel, Jennifer Nerlich de Vogel
    >>> USt-IdNr.: DE284122352
    >>> Fax (040) 5247 6322, Email: lars.vo...@vogella.com
    <mailto:lars.vo...@vogella.com>, Web: http://www.vogella.com
    >>> _______________________________________________
    >>> equinox-dev mailing list
    >>> equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    >>> To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev
    >>
    >>
    >>
    >> --
    >> Best regards,
    >> Dmytro Pishchukhin
    >> _______________________________________________
    >> equinox-dev mailing list
    >> equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    >> To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev
    >
    > _______________________________________________
    > equinox-dev mailing list
    > equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    > To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev



    --
    Eclipse Platform project co-lead
    CEO vogella GmbH

    Haindaalwisch 17a, 22395 Hamburg
    Amtsgericht Hamburg: HRB 127058
    Geschäftsführer: Lars Vogel, Jennifer Nerlich de Vogel
    USt-IdNr.: DE284122352
    Fax (040) 5247 6322, Email: lars.vo...@vogella.com
    <mailto:lars.vo...@vogella.com>, Web: http://www.vogella.com

    On Tue, Jul 28, 2020 at 9:11 PM Mark Hoffmann
    <mark.hoffm...@web.de <mailto:mark.hoffm...@web.de>> wrote:
    >
    > Hi Lars,
    >
    > For EclipseLink you should also place a jaxb.properties file in
    the package where the entites are located or otherwise/better use the
    >
    >
    
-Djavax.xml.bind.JAXBContextFactory=org.eclipse.persistence.jaxb.JAXBContextFactory
    >
    > System Property
    >
    > Am 28.07.20 um 15:07 schrieb Neil Bartlett:
    >
    > Hi Lars,
    >
    > Dmytro is correct, the jaxb-api and javax.activation bundles are
    required to provide the JAXB API on Java 11. You will also need an
    implementation of the API... the org.eclipse.persistence.core and
    org.eclipse.persistence.moxy bundles from EclipseLink provide this.
    >
    > I have had JAXB working with RCP for some time on J11 but
    unfortunately cannot share the code because it is commercial.
    >
    > Neil
    >
    > On Tue, 28 Jul 2020 at 14:03, Dmytro Pishchukhin
    <dmytro.pishchuk...@gmail.com
    <mailto:dmytro.pishchuk...@gmail.com>> wrote:
    >>
    >> Hi Lars,
    >>
    >> Try to use 2 bundles to resolve JAXB packages:
    >> - jaxb-api (javax.xml.bind:jaxb-api:2.3.1)
    >> - javax.activation (com.sun.activation:javax.activation:1.2.0)
    >>
    >> On Tue, Jul 28, 2020 at 1:56 PM Lars Vogel
    <lars.vo...@vogella.com <mailto:lars.vo...@vogella.com>> wrote:
    >>>
    >>> Friends of OSGi,
    >>>
    >>> Is anyone aware of an example / description of how to use JAXB
    with
    >>> Java 11 in OSGI (Eclipse RCP)? If yes, please share it with me.
    >>>
    >>> The examples I found for Java 11 are not inside OSGi and fail
    for me.
    >>>
    >>> Best regards, Lars
    >>>
    >>>
    >>>
    >>> --
    >>> Eclipse Platform project co-lead
    >>> CEO vogella GmbH
    >>>
    >>> Haindaalwisch 17a, 22395 Hamburg
    >>> Amtsgericht Hamburg: HRB 127058
    >>> Geschäftsführer: Lars Vogel, Jennifer Nerlich de Vogel
    >>> USt-IdNr.: DE284122352
    >>> Fax (040) 5247 6322, Email: lars.vo...@vogella.com
    <mailto:lars.vo...@vogella.com>, Web: http://www.vogella.com
    >>> _______________________________________________
    >>> equinox-dev mailing list
    >>> equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    >>> To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev
    >>
    >>
    >>
    >> --
    >> Best regards,
    >> Dmytro Pishchukhin
    >> _______________________________________________
    >> equinox-dev mailing list
    >> equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    >> To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev
    >
    >
    > _______________________________________________
    > equinox-dev mailing list
    > equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    > To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev
    >
    > --
    > Mark Hoffmann
    >
    > E-Mail: mark.hoffm...@web.de <mailto:mark.hoffm...@web.de>
    >
    > _______________________________________________
    > equinox-dev mailing list
    > equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    > To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev



    --
    Eclipse Platform project co-lead
    CEO vogella GmbH

    Haindaalwisch 17a, 22395 Hamburg
    Amtsgericht Hamburg: HRB 127058
    Geschäftsführer: Lars Vogel, Jennifer Nerlich de Vogel
    USt-IdNr.: DE284122352
    Fax (040) 5247 6322, Email: lars.vo...@vogella.com
    <mailto:lars.vo...@vogella.com>, Web: http://www.vogella.com
    _______________________________________________
    equinox-dev mailing list
    equinox-dev@eclipse.org <mailto:equinox-dev@eclipse.org>
    To unsubscribe from this list, visit
    https://www.eclipse.org/mailman/listinfo/equinox-dev


_______________________________________________
equinox-dev mailing list
equinox-dev@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/equinox-dev

--
Mark Hoffmann

E-Mail: mark.hoffm...@web.de

_______________________________________________
equinox-dev mailing list
equinox-dev@eclipse.org
To unsubscribe from this list, visit 
https://www.eclipse.org/mailman/listinfo/equinox-dev

Reply via email to