0

I am using Apache CXF to call a SOAP web service. CXF uses the javax.annotation.Resource annotation, which is part of Java 8, however my application is throwing a ClassNotFoundException for it;

java.lang.ClassNotFoundException: javax.annotation.Resource not found by my-application-name [164]
    at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1558)
    at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
    at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:1998)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
 [wrapped] java.lang.NoClassDefFoundError: javax/annotation/Resource
    at org.apache.cxf.common.injection.ResourceInjector.<clinit>(ResourceInjector.java:59)
    at org.apache.cxf.bus.extension.ExtensionManagerImpl.loadAndRegister(ExtensionManagerImpl.java:222)
    at org.apache.cxf.bus.extension.ExtensionManagerImpl.activateAllByType(ExtensionManagerImpl.java:140)
    at org.apache.cxf.bus.extension.ExtensionManagerBus.<init>(ExtensionManagerBus.java:126)
    at org.apache.cxf.bus.extension.ExtensionManagerBus.<init>(ExtensionManagerBus.java:134)
    at org.apache.cxf.bus.CXFBusFactory.createBus(CXFBusFactory.java:40)
    at org.apache.cxf.bus.CXFBusFactory.createBus(CXFBusFactory.java:36)
    at org.apache.cxf.bus.CXFBusFactory.createBus(CXFBusFactory.java:32)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:146)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:122)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:94)
    at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:83)
    at org.apache.cxf.BusFactory.getDefaultBus(BusFactory.java:106)
    at org.apache.cxf.BusFactory.createThreadBus(BusFactory.java:216)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:206)
    at org.apache.cxf.BusFactory.getThreadDefaultBus(BusFactory.java:193)
    at org.apache.cxf.jaxws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:97)
    at javax.xml.ws.Service.<init>(Service.java:77)

What could be causing my application to fail on this standard class? I am using Java 8u91 and I can see the class in D:\dev\java\jdk_8u91\jre\lib\rt.jar.

Qwerky
  • 18,217
  • 6
  • 44
  • 80
  • Is there a chance that you have 2 versions of JVM on your machine? – AlexR Aug 24 '16 at 11:16
  • @AlexR I have 4 Java installs :) but I am sure that I'm running the right one. – Qwerky Aug 24 '16 at 11:20
  • I believe you are not. The case is that this class was in separate jar prior java 8. I guess that somehow you are using wrong jvm or at least wrong rt.jar. Check all parameters that you are using to run java – AlexR Aug 24 '16 at 11:41
  • 2
    Maybe it's because of this OSGI feature: [http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-faq.html#why-is-my-bundle-not-able-to-see-annotations-at-run-time](http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-faq.html#why-is-my-bundle-not-able-to-see-annotations-at-run-time) – eltabo Aug 24 '16 at 11:57

1 Answers1

0

The problem was OSGI related. My application uses the maven-bundle-plugin to create the OSGI bundle, but there were some key packages that were not imported.

<Import-Package>
    javax.activation.*,
    javax.annotation.*,
    javax.jws.*,
    ..more imports..
</Import-Package>

Once javax.annotation.* was added to the imported packages the problem was solved.

Qwerky
  • 18,217
  • 6
  • 44
  • 80