Make JAXB within org.eclipse.fx.core work with Java 11
Opened this issue · 7 comments
- Set the correct ContextClassLoader for creating the JAXBContext
- Add optional dependency to javax.xml.bind.*
- Add optional dependency to com.sun.xm.bind.*
Is this the Reason for my ClassNotFoundException, when i want to use the 'PerspectiveSwitcherComponent'?
I have used the newest Nighly from http://download.eclipse.org/efxclipse/runtime-nightly/site but i'm getting this Exception?
Should this Error not removed with this PR ?
`!MESSAGE Unable to create class 'org.eclipse.fx.ui.workbench.fx.perspective.PerspectiveSwitcherComponent' from bundle '177'
!STACK 0
org.eclipse.e4.core.di.InjectionException: org.eclipse.e4.core.di.InjectionException: java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory cannot be found by org.eclipse.fx.core_3.7.0.202103260600]
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:68)
at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:1002)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:139)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:408)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:331)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:202)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:91)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:60)
at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42)
at org.eclipse.fx.ui.workbench.renderers.base.BaseToolControlRenderer.doProcessContent(BaseToolControlRenderer.java:55)
at org.eclipse.fx.ui.workbench.renderers.base.BaseToolControlRenderer.doProcessContent(BaseToolControlRenderer.java:1)
at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.processContent(BaseRenderer.java:757)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:248)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:327)
at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.engineCreateWidget(BaseRenderer.java:663)
at org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.doProcessContent(BaseToolBarRenderer.java:64)
at org.eclipse.fx.ui.workbench.renderers.base.BaseToolBarRenderer.doProcessContent(BaseToolBarRenderer.java:1)
at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.processContent(BaseRenderer.java:757)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:248)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:327)
at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.engineCreateWidget(BaseRenderer.java:663)
at org.eclipse.fx.ui.workbench.renderers.base.BaseTrimBarRenderer.doProcessContent(BaseTrimBarRenderer.java:56)
at org.eclipse.fx.ui.workbench.renderers.base.BaseTrimBarRenderer.doProcessContent(BaseTrimBarRenderer.java:1)
at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.processContent(BaseRenderer.java:757)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:248)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:327)
at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.engineCreateWidget(BaseRenderer.java:663)
at org.eclipse.fx.ui.workbench.renderers.base.BaseWindowRenderer.doProcessContent(BaseWindowRenderer.java:420)
at org.eclipse.fx.ui.workbench.renderers.base.BaseWindowRenderer.doProcessContent(BaseWindowRenderer.java:1)
at org.eclipse.fx.ui.workbench.renderers.base.BaseRenderer.processContent(BaseRenderer.java:757)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:248)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.createGui(PartRenderingEngine.java:327)
at org.eclipse.fx.ui.workbench.fx.PartRenderingEngine.run(PartRenderingEngine.java:482)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
at org.eclipse.fx.ui.workbench.fx.E4Application$1.lambda$0(E4Application.java:259)
at org.eclipse.fx.ui.controls.internal.FXThreadSynchronizeImpl.syncExec(FXThreadSynchronizeImpl.java:109)
at org.eclipse.fx.ui.workbench.fx.E4Application$1.run(E4Application.java:249)
at org.eclipse.fx.ui.workbench.fx.E4Application.jfxStart(E4Application.java:271)
at org.eclipse.fx.ui.workbench.fx.DefaultJFXApp.start(DefaultJFXApp.java:60)
at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.eclipse.e4.core.di.InjectionException: java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath. - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory cannot be found by org.eclipse.fx.core_3.7.0.202103260600]
at org.eclipse.e4.core.internal.di.ConstructorRequestor.execute(ConstructorRequestor.java:55)
at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:406)
at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:331)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:202)
at org.eclipse.fx.ui.workbench.fx.perspective.PerspectiveSwitcherComponent.init(PerspectiveSwitcherComponent.java:28)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
... 47 more
Caused by: java.lang.RuntimeException: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath. - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory cannot be found by org.eclipse.fx.core_3.7.0.202103260600]
at org.eclipse.fx.core.internal.JAXBObjectSerializer.lambda$1(JAXBObjectSerializer.java:86)
at org.eclipse.fx.core.internal.JAXBObjectSerializer.runWithThreadContextCL(JAXBObjectSerializer.java:156)
at org.eclipse.fx.core.internal.JAXBObjectSerializer.serializeCollection(JAXBObjectSerializer.java:67)
at org.eclipse.fx.core.di.context.internal.PreferenceValue.publish(PreferenceValue.java:195)
at org.eclipse.fx.ui.workbench.fx.perspective.PerspectiveSwitcherNode.publishNewPerspectiveList(PerspectiveSwitcherNode.java:150)
at org.eclipse.fx.ui.workbench.fx.perspective.PerspectiveSwitcherNode.(PerspectiveSwitcherNode.java:131)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.eclipse.e4.core.internal.di.ConstructorRequestor.execute(ConstructorRequestor.java:43)
... 56 more
Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath. - with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory cannot be found by org.eclipse.fx.core_3.7.0.202103260600]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:278)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:421)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:721)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:662)
at org.eclipse.fx.core.internal.JAXBObjectSerializer.lambda$1(JAXBObjectSerializer.java:77)
... 66 more
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory cannot be found by org.eclipse.fx.core_3.7.0.202103260600
at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:516)
at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:171)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:122)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:155)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:276)
... 70 more`
My wild guess is that your target does not contain JAXB libs. You need to add them yourself.
I have added the dependencies to my target and my Launch-Config:
jaxb-api,
com.sun.xml.bind.jaxb-core,
com.sun.xml.bind.jaxb-impl
from orbit or from where did you get them - @christian-baumann correct me but i think in our customer projects we added:
- javax.xml.bind
- com.sun.xml.bind
from orbit
In order to make JAXB work with Java 11 two things are necessary:
- As e(fx)clipse is still compiled with JDK 1.8 you have to make JAXB avaiable within your Application-Target. The easiest way is to use the Orbit P2 reposity: https://download.eclipse.org/tools/orbit/downloads/
You will need to bundles javax.xml.bind and com.sun.xml.bind. - You have to configure the FQN of the JAXB ContextFactory by setting the system property javax.xml.bind.JAXBContext. This can be done by starting your application with the VM argument -Djavax.xml.bind.JAXBContext=com.sun.xml.bind.v2.ContextFactory. We cannot set this over a jaxb.properties file within e(fx)clipse as it still has to be compatible with Java 1.8 and, as you can see in your stack trace, the ContextFactory package has changed from com.sun.xml.internal.bind.v2 to com.sun.xml.bind.v2.
Thanks for your comments. I have tried to follow your recommendations, but the Problem is the same.
Because we use in our app json and no xml and the only reason to i want to add is the PerspectiveSwitcherComponent i have decided to stop more wasting time and build my own PerspectiveSwitcher.