Skip to main content

[java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory

3 replies [Last post]
sivaram
Offline
Joined: 2006-08-03

Hi All,

I am newbie to both osgi and glashfish. I have downloaded the latest glashfish 3.1.2.2. and writen a sample osgi bundle.

I am getting the following error while creating JAXBContext instance in the server:

java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory not found by ]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:361)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:446)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:409)
at com.cultagent.gr.hotelde.Activator.start(Activator.java:34)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:641)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977)
at org.apache.felix.framework.Felix.startBundle(Felix.java:1895)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1175)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1153)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.processAllBundles(DirectoryWatcher.java:1146)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:456)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:263)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.internal.bind.v2.ContextFactory not found by com.cultagent.gr.hotelde [265]
at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:573)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:145)
... 13 more

can any body please suggest me how to resolve this issue.

Thanks in advance.

Regards,
Siva Ram.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ss141213
Offline
Joined: 2005-03-30

Hi,

Instead of deploying using FileInstall, could you deploy like this:

asadmin deploy --type osgi

That might fix JAXBContext not being able to find
com.sun.xml.internal.bind.v2.ContextFactory.

I am actually surprised you are facing this issue, because to my
knowledge, we had fixed this bug by making changes to JAXB as described
in [1]. I will find more about that issue. What JDK are you using?

Thanks,
Sahoo

[1] http://java.net/jira/browse/GLASSFISH-11748

On Thursday 27 September 2012 02:26 PM, forums@java.net wrote:
> Hi All, I am newbie to both osgi and glashfish. I have downloaded the
> latest
> glashfish 3.1.2.2. and writen a sample osgi bundle. I am getting the
> following error while creating JAXBContext instance in the server:
> java.lang.ClassNotFoundException:
> com.sun.xml.internal.bind.v2.ContextFactory
> not found by ] at
> javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148) at
> javax.xml.bind.ContextFinder.find(ContextFinder.java:361) at
> javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:446) at
> javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:409) at
> com.cultagent.gr.hotelde.Activator.start(Activator.java:34) at
> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:641)
>
> at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977) at
> org.apache.felix.framework.Felix.startBundle(Felix.java:1895) at
> org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944) at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1175)
>
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1153)
>
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.processAllBundles(DirectoryWatcher.java:1146)
>
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:456)
>
> at
> org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:263)
>
> Caused by: java.lang.ClassNotFoundException:
> com.sun.xml.internal.bind.v2.ContextFactory not found by
> com.cultagent.gr.hotelde [265] at
> org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
>
> at
> org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
>
> at
> org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
>
> at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at
> javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:573) at
> javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:145) ...
> 13 more
> can any body please suggest me how to resolve this issue. Thanks in
> advance.
> Regards, Siva Ram.
>
> --
>
> [Message sent by forum member 'sivaram']
>
> View Post: http://forums.java.net/node/890740
>
>

ss141213
Offline
Joined: 2005-03-30

I quickly tried to run the test case attached to the issue [1] I had
referenced in my email below and it is working. I will go ahead and add
it in our regression test suite.

I suggest you download and run it first. You also tell us what you are
doing differently.

Thanks,
Sahoo

On Thursday 27 September 2012 04:59 PM, Sahoo wrote:
> Hi,
>
> Instead of deploying using FileInstall, could you deploy like this:
>
> asadmin deploy --type osgi
>
> That might fix JAXBContext not being able to find
> com.sun.xml.internal.bind.v2.ContextFactory.
>
> I am actually surprised you are facing this issue, because to my
> knowledge, we had fixed this bug by making changes to JAXB as
> described in [1]. I will find more about that issue. What JDK are you
> using?
>
> Thanks,
> Sahoo
>
> [1] http://java.net/jira/browse/GLASSFISH-11748
>
> On Thursday 27 September 2012 02:26 PM, forums@java.net wrote:
>> Hi All, I am newbie to both osgi and glashfish. I have downloaded the
>> latest
>> glashfish 3.1.2.2. and writen a sample osgi bundle. I am getting the
>> following error while creating JAXBContext instance in the server:
>> java.lang.ClassNotFoundException:
>> com.sun.xml.internal.bind.v2.ContextFactory
>> not found by ] at
>> javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:148) at
>> javax.xml.bind.ContextFinder.find(ContextFinder.java:361) at
>> javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:446) at
>> javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:409) at
>> com.cultagent.gr.hotelde.Activator.start(Activator.java:34) at
>> org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:641)
>>
>> at org.apache.felix.framework.Felix.activateBundle(Felix.java:1977) at
>> org.apache.felix.framework.Felix.startBundle(Felix.java:1895) at
>> org.apache.felix.framework.BundleImpl.start(BundleImpl.java:944) at
>> org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1175)
>>
>> at
>> org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:1153)
>>
>> at
>> org.apache.felix.fileinstall.internal.DirectoryWatcher.processAllBundles(DirectoryWatcher.java:1146)
>>
>> at
>> org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:456)
>>
>> at
>> org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:263)
>>
>> Caused by: java.lang.ClassNotFoundException:
>> com.sun.xml.internal.bind.v2.ContextFactory not found by
>> com.cultagent.gr.hotelde [265] at
>> org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1460)
>>
>> at
>> org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:72)
>>
>> at
>> org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1843)
>>
>> at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at
>> javax.xml.bind.ContextFinder.safeLoadClass(ContextFinder.java:573) at
>> javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:145) ...
>> 13 more
>> can any body please suggest me how to resolve this issue. Thanks in
>> advance.
>> Regards, Siva Ram.
>>
>> --
>>
>> [Message sent by forum member 'sivaram']
>>
>> View Post: http://forums.java.net/node/890740
>>
>>
>

ra2085
Offline
Joined: 2010-12-21

I get the same Exception when trying to get a new JAXBContext instance like this (Using the test case [1] of course):

JAXBContext jc = JAXBContext.newInstance(ObjectFactory.class.getPackage().getName(),ObjectFactory.class.getClassLoader());

If I leave the test case [1] as it is, the bundle deploys correctly. However, if I verify the sets of classes included in the context using JAXBContext.toString(), it only includes these:

Classes known to this context:
  [B
  boolean
  byte
  char
  com.sun.xml.bind.api.CompositeStructure
  double
  float
  int
  java.awt.Image
  java.io.File
  java.lang.Boolean
  java.lang.Byte
  java.lang.Character
  java.lang.Class
  java.lang.Double
  java.lang.Float
  java.lang.Integer
  java.lang.Long
  java.lang.Object
  java.lang.Short
  java.lang.String
  java.lang.Void
  java.math.BigDecimal
  java.math.BigInteger
  java.net.URI
  java.net.URL
  java.util.Calendar
  java.util.Date
  java.util.GregorianCalendar
  java.util.UUID
  javax.activation.DataHandler
  javax.xml.bind.JAXBElement
  javax.xml.datatype.Duration
  javax.xml.datatype.XMLGregorianCalendar
  javax.xml.namespace.QName
  javax.xml.transform.Source
  long
  sahoo.metainfservicetest.ObjectFactory
  short
  void
|#]

I'm not sure if this is the expected behavior. I thought it would include all the classes referenced in the ObjectFactory class, just like in a normal EE app (not an osgi bundle). Does anyone have some insight on this?

Thanks.