equinox jetty NoClassDefFoundError: SslContextFactory - osgi

i have a osgi project in indigo ide, which use equinox 3.7.0 + jetty 7.5.1, now i upgrade ide to juno, which contain equinox 3.8.0 + jetty 8.1.3, so,
the tragedy go on:
when compiling, complain accesible restrictation on SslContextFactory's methods, i resolved it by editing it's access rules in build path.
when running, have a error, say
java.lang.NoClassDefFoundError: org/eclipse/jetty/util/ssl/SslContextFactory
now i have no idea, thanks for ur help.

The access rules are there for a reason.... by hiding the build-time error, you just made the runtime error appear.
The proper solution is to import the package org.eclipse.jetty.util.ssl in your bundle.
If you use a tool such as Bndtools then these Import-Package dependencies will be detected and generated automatically.

Related

Why third party dependency is required exclusively from OSGi container even if I have it in my maven dependencies?

I want to know why OSGi do not respect the maven dependenceis.
I want to create one app in OSGi(AEM). I want to communicate(CRUD) to the database with the help of JPA(eclipselink).
I created maven project with aem-archetype.
Added all required dependencies(of JPA) into my maven project's pom file.
No errors in Eclipse, I built the project via mvn clean install and installed it into AEM(CQ5) via mvn sling:install. All good till now. No Errors.
But when I go and see my bundle in the felix console, I see that it is not Active but in Installed state.The error reported is that it could not resolve the javax.persistence package.
I was puzzled, I searched and I read about it here -
You have to make sure that you place the same version in another
bundle and deploy first. https://forums.adobe.com/thread/2325007
I converted JPA jar to OSGi bundle and installed in my OSGi container, and the error was gone. Great!
But why OSGi is not watching out for the dependencies I wrote in pom.xml of my maven project. Why it needs JPA strictly from OSGi bundle?
Maybe this is due to any architectural benefit, but could anyone please explain me here about this behaviour of OSGi? And why/how this feature of OSGi is useful ?
The <dependency> section of your Maven POM only covers your compile time dependencies. That means when you run Maven to build your project those dependencies are used to compile the source code and build your bundle. Maven itself is not aware of AEM or OSGi or any other platform or framework (e.g. Spring).
Maven just compiles your code.
You, as a developer, are responsible that all those required compile time dependencies are also available at runtime.
What we usually do is to create an AEM content package Maven module and put all of our required third party dependencies (e.g. JPA bundles) into it. This content package is then deployed by Maven so that those dependencies are also available at runtime.
Reason is: what you are adding as dependency is getting added in build path of your project and being available for your classes.When you run mvn install,it checks presence of all dependency and creates a bundle/jar for you.By default this bundle has only your project classes not other dependencies.
You need to check in depfinder whether external dependencies are already there in OSGi container,if not you have to load them in OSGi container either by embedding external dependencies in your bundle with the help of maven-bundle-plugin present in pom.xml or by making a bundle of jar file(I wont recommend that)which you have done.
I hope this helps!

CXF - ClassCastException (SEIStub/ClientProxy) in Equinox

I am getting following exception inside Equinox OSGI :
Getting java.lang.ClassCastException: com.sun.xml.ws.client.sei.SEIStub cannot be cast to org.apache.cxf.frontend.ClientProxy
Please advise.
It looks like you accidently use the jax-ws stack that is part of the jdk instead of CXF. I guess the reason is an incorrect deployment of CXF in your OSGi runtime.
You will need to not export the jax-ws API packages from the framework and instead install the jax-ws API from servicemix bundles. You can try to install Apache CXF in Apache Karaf to see how the correct deployment should look like.
To set the packages to be exported by the framework use the framework property org.osgi.framework.system.packages. See also Apache Felix configuration. Unfortunately there is no option to remove a package from the exported packages. If you use this option then you need to specify all packages that the framework exports. The default can be found in the felix jar in a property file default.properties.

Spring Boot 1.4.3 Embedded Tomcat NoSuchMethodError StringManager.getManager

I have update my project to use Spring BOOT 1.4.3. The code compiles and runs without issues from Eclipse Neon 1.
But when I run from command line
mvn clean install -DskipTests
java -jar myweb\target\my-web-1.0-SNAPSHOT.jar
I get runtime error and tomcat is not starting
Caused by: java.lang.NoSuchMethodError: org.apache.tomcat.util.res.StringManager.getManager(Ljava/lang/Class;)Lorg/apache/tomcat/util/res/StringManager;
at org.apache.catalina.util.LifecycleBase.<clinit>(LifecycleBase.java:43) ~[tomcat-embed-core-8.5.6.jar!/:8.5.6]
Please can you tell why? How to find which tomcat is used at runtime, as my understand is that 8.5.6 is having compile scope(?)
Please help. If the suggestion is to use tomcat.version in properties of POM file or add tomcat-juli dependency, then please help me understand why it is required?
Impatient stackoverflow'ers dont just flog new comers only because you can do. You can easily ask if you want my POM, but I used just spring-boot-starter-web thats it.
For this kind of problem, it's often due to multiple jar having the same class inside your classpath, so :
Find where this class / method could come from, by opening the type popup (CTRL + SHIFT + T in Eclipse). It will display you every jar in your classpath that contains the class.
Open the class in each jar to see which one contains your method and which one don't.
Display the dependency hierarchy of your project with mvn dependency:tree
If the 2 jars are in your classpath, you might exclude the one that don't contain the method.

Karaf development

Im currently develop bundles for karaf and have some questions...
I wrote a bundle/webservice based on cxf, I try to deploy it in karaf but it could not start that bundle because it could not resolve some packages e.g.
org.osgi.framework.BundleException: Unresolved constraint in bundle org.springframework.aop [56]: Unable to resolve 56.0: missing
requirement [56.0] package; (&(package=org.aopalliance.aop)(version>=1.0.0)(!(version>=2.0.0)))
so here is a question, this package dependency comes from spring-aop (3.1.0.RELEASE), so where is the problem? what dependency is missing? how can I solve such problems?
In that case i did not clearly understand the development process. should i deploy all missing bundles in deploy? because i would like to keep thirdparty libs spereated from my developed bundles. And what bundles i have to deploy? Is it a trial and error process? Is there a common way to let maven do the dependency stuff?
I discovered a folder "system" and read on the docu that it is a repository like maven, is it for the features?
I had for test cases a karaf with some pre deployed bundles and put my webservice bundle into it, but again execeptions...
Caused by: java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
What dependency is missing?
I already read the tutorial about camel and karaf, but it did not explain the deployment stuff, so could anyone suggest me a good tutorial?
Thanks!
Chris
Short answer
Scroll down to the bit referring to "camel-cxf" and run the two commands features:addurl and features:install. I have a feeling this will resolve all your problems.
spring-aop
On Karaf console type:
exports | grep org.aopalliance.aop
I think you'll see lines like:
XX org.aopalliance.aop; version=3.1.0.RELEASE
So while the spring-aop bundle has the right packages they're the wrong version, the range being requested is >=1.0.0 and <2.0.0, so 3.1.0 doesn't satisfy that.
Deploying/Installing
You can drop bundles into ${karaf.home}/deploy or use the console.
You can install maven bundles from the Karaf console with:
install -s mvn:groupId/artifactId/version/packaging/classifier
Where -s starts the bundle and packaging/classifier are optional.
You can find a lot of OSGi ready maven dependencies here http://ebr.springsource.com/repository/app/ - I had a quick look but your spring aop dependency is very old, what version of CXF are you using?
Read up about Karaf features - they're basically XML files that list suites of bundles that can be installed. Very useful for deploying large numbers of bundles and they can be installed into a maven repository.
There are some standard features available in Karaf, try:
features:install war
This will give you a jetty webcontainer and may resolve your ClassNotFoundException: javax.servlet.http.HttpServlet as long as it's the right version
Camel also has a features file which probably sort all your issues, try this:
features:addurl mvn:org.apache.camel.karaf/apache-camel/2.9.0/xml/features
features:install camel-cxf
Tutorials
There's quite a bit available, some on http://karaf.apache.org and http://fusesource.com but also take a look at the PDF manual that comes in the Karaf distribution.
Always beware that info may be out-of-date
Please post your MANIFEST.MF file. I think you didn't not mention the tag in maven-bundle-plugin dependency.

Tomcat Jersey SPI Error

I have a Jersey (1.4) app deployed on Tomcat 5.5, when Tomcat starts up I can see its loading all the resources and providers. But as soon as I access any of the web services I get this strange error
java.lang.NoClassDefFoundError: com/sun/jersey/spi/inject/Errors$Closure
I spent good long time finding out what's going on but had no luck.
I converted maven project into eclipse project using mvn eclipse:eclipse -Dwtpversion=1.5.
Any ideas?
I got this error when I also had a nuxeo related dependancy in my maven pom.xml, which itself has a dependency on jersey libraries, but at an earlier version (1.1.5 to be specific).
I changed the pom to depend on the latest version of jersey-core, jersey-server and jersey-client dependencies and ran mvn eclipse:eclipse and the problem went away!
There must have been a class clash involved.

Resources