I wrote a Liferay module and deployed it successfully.
Then I added this line in build.gradle's dependencies section:
compileOnly group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.3'
After running ./gradlew eclipse I can use the library with no problem in Eclipse. But deployment fails:
12:29:35,454 WARN [fileinstall-/home/nico/liferay/osgi/modules][org_apache_felix_fileinstall:103] Error while starting bundle: file:/home/nico/liferay-dxp-digital-enterprise-7.0-sp3/osgi/modules/de.nico.mymodule-1.0.0.jar
org.osgi.framework.BundleException: Could not resolve module: de.nico.mymodule [1085]_ Unresolved requirement: Import-Package: org.apache.http; version="4.5.3"_ [Sanitized]
at org.eclipse.osgi.container.Module.start(Module.java:429)
at org.eclipse.osgi.internal.framework.EquinoxBundle.start(EquinoxBundle.java:402)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1253)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1225)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)
at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)
I have no idea why it is looking for org.apache.http and not org.apache.httpcomponents.
Here is my bnd.bnd:
Bundle-SymbolicName: de.nico.mymodule
Bundle-Version: 1.0.0
Liferay-Require-SchemaVersion: 1.0.0
How to investigate this problem?
I don't want to download/add the JAR manually.
In your bnd.bnd
add this code ..
Import-Package:\
!org.apache.*,\
\
*
the further investigations will start at the exception messsage. It says that the following requirement is not present at RUNTIME:
Import-Package: org.apache.http; version="4.5.3"
I'm assuming that it's one of the following:
you didn't deploy the httpcomponents (or a version you need .. see Semantic Versioning) libraries to Liferay (as compile works, while deployment fails)
httpcomponents might not be packaged as OSGi bundles. In that case you'll have to decide how to make the code available. Good starting points for more information are the official docs (thanks Andrea, promoting this from the comments) and David Nebinger's blog article
How you add those dependencies to Liferay's runtime is up to you. If the dependencies are OSGi bundles, you can download&deploy them directly. If they're no OSGi bundles, follow one of the techniques described in the linked articles.
Related
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!
I am attempting to run an application on Apache Felix, using the Felix Dependency bundles. The container is, for some reason, not loading my bundles.
I am doing my development using Bndtools in Eclipse. I am using the Amdatu bundles.
The bundles I am concerned about are the bundles that are in my "Run Requirements":
org.apache.felix.dependencymanager
org.apache.felix.dependencymanager.shell
org.apache.felix.dependencymanager.runtime
osgi.core
osgi.cmpn
All of the above bundles are taken from the Amdatu repository.
I have two bundles which I created:
com.test.demo.reader
com.test.demo.listener
And these bundles are built using org.apache.felix.dependencymanager and osgi.core.
When I attempt to run OSGi, I am getting the following failures:
! could not resolve the bundles: [com.test.demo.reader-1.0.0 Unresolved constraint in bundle
com.test.demo.reader [8]: Unable to resolve 8.0: missing requirement
[8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)(!(version>=4.0.0))),
com.test.demo.listener-1.0.0 Unresolved constraint in bundle com.test.demo.listener [9]:
Unable to resolve 9.0: missing requirement [9.0] osgi.wiring.package;
(&(osgi.wiring.package=com.test.demo.reader)(version>=1.0.0)(!(version>=2.0.0)))
[caused by: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package;
(&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)(!(version>=4.0.0)))]]
and
! Failed to start bundle com.test.demo.reader-1.0.0, exception Unresolved constraint in
bundle com.test.demo.reader [8]: Unable to resolve 8.0: missing requirement [8.0]
osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)
(!(version>=4.0.0)))
and more
! Failed to start bundle com.test.demo.listener-1.0.0, exception Unresolved constraint in
bundle com.test.demo.listener [9]: Unable to resolve 9.0:
missing requirement [9.0] osgi.wiring.package; (&(osgi.wiring.package=com.test.demo.reader)
(version>=1.0.0)(!(version>=2.0.0))) [caused by: Unable to resolve 8.0: missing requirement
[8.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.felix.dm)(version>=3.0.0)
(!(version>=4.0.0)))]
I think I understand what is happening: apparently the org.apache.dm package being used is a version that is somehow incompatible with my bundles. But that doesn't make any sense, because according to the Felix documentation the org.apache.dm package is in the org.apache.felix.dependencymanager bundle. That bundle is from the Amdatu repository and it is the only version of the bundle I am using with my application! How is the version incompatible with my bundles when theirs is the only version that my bundles know about???
Someone please advise. What is causing this failure an how can I fix it?
The problem was the runtime I was running and what appears to be a bug in the Amdatu plugin.
I would not advise using the Amdatu configuration in your OSGi project. Not in its current form.
The various Felix Dependency bundles that I have been using from Amdatu are apparently intended to run under Felix version 5. Unfortunately, the Amdatu environment (the "Amdatu Configuration" that you can select when you choose a configuration template for your project) does not load Version 5. When you select the "Bundle- Hub configuration", your choice of runtime environments includes all Felix environments from Version 4.0.2 to Version 5.2, as well as several versions of Equinox. When you select the "Amdatu Configuration" you only runtime choices are Felix 4.0.2 and Felix 4.2.0.
I was using 4.2.0 Felix, and as a result the dependency bundles were not working.
The Amdatu environment in its current form is unusable in Bndtools. It apparently supplies the right bundles for Version 5 but does not provide that environment for the user.
I did try manually changing the runtime environment io Version 5.2. This did not work because apparently when you select a template, Bndtools puts together whatever runtimes are associated with the template. Because the Amdatu template does not include Felix version 5, the runtime environment is unavailable.
In order to get my application to run, I had to create a new project that used the "Bundle- Hub" template and manually download the dependency bundles from the Felix website and include them in my buil and runtime environments. Unfortunately, neither Bndtools nor Amdatu provides any way to add the Amdatu bundles to project after a template is selected. This means that instead of using the ready- made bundles from Amdatu, you have to go out to the source sites and manually include them.
I will probably ty and find a way to create a new repository that can be included in projects and contains all the Amdatu bundles, then include that repository in the "Bundle- Hub" template. I will also report the problems with environments (as well as seversl other problems I've seen) to the Amdatu folks.
In the meantime, my application runs smoothly now that I have set up the right runtime environment.
Special thanks to earcam, whose questions in the comment above gave me a clue as to what to start looking at to solve this problem...
I am using the following camel packages in my Maven project:
camel-core
camel-jms
camel-jaxb
camel-quartz
camel-bindy
camel-ftp
And when all these are using version 2.8.0 my server starts up fine and the app works ok. But if I update the camel version to anything higher like 2.10.0 then I get the following exception on startup and not sure which of these is causing this issue:
Caused by: org.apache.camel.TypeConverterLoaderException: Failed to load type converters because of: Cannot find any type converter classes from the following packages: [org.apache.camel.component.file.remote]
Any help would be much appreciated?
Maybe another library of your project is using a different version of camel.
You can check the camel dependency tree of your project with this maven command:
mvn dependency:tree -Dverbose -Dincludes=camel-core
In verbose mode, the dependency tree shows dependencies that were omitted for being a duplicate of another, conflicting with another's version and/or scope, and introducing a cycle into the dependency tree.
Here are some reference links:
https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html
https://maven.apache.org/plugins/maven-dependency-plugin/examples/resolving-conflicts-using-the-dependency-tree.html
I have a large Java application that's mostly networking and file processing with lots of DB access. There's no UI. We expose a few web services (embedded Netty) and call some external rest web services. The project is built with Ant. It's about 10 different jars plus maybe 30-40 libraries.
My current task is to move the project to the OSGi framework. I am startling slowly.
Following the examples in "OSGi In Action" chapter 6, I have used the BND ant task to put the entire project into one huge jar file. This worked. I am able to run the program using java -jar. Here's my current .bnd file:
-output: bundle/MerchantServicesBundle.jar
-include: manifest/merchantservices.manifest
Bundle-Name: MerchantServices
Bundle-SymbolicName: com.shopping.services.merchant
Bundle-Version: 4.1
Main-Class: com.shopping.merchant.services.netty.MerchantServices
Class-Path: /home/ppantera/repositories/MerchantJava/modules/MerchantServices/conf/
Private-Package: *
I am using Apache Felix 4.0.3. From the Gogo shell I can install the bundle but when I start it I get this:
org.osgi.framework.BundleException: Unresolved constraint in bundle com.shopping.services.merchant [8]: Unable to resolve 8.0: missing requirement [8.0] osgi.wiring.package; (osgi.wiring.package=android.dalvik)
Why does Felix think this is an Android project?
There doesn't seem to be much about this on the 'net. Would you recommend using an older version of Felix so I'm sheltered from the newer OSGi features that could cause me confusion?
I tried adding this to my .bnd file:
Require-Capability: osgi.ee; filter:="(&(osgi.ee=JavaSE)(version>=1.7))"
That didn't help. What am I doing wrong? Any other pointers?
It looks like somehow bnd detected a requirement to an Android package, and added that to the MANIFEST.MF, it could be in your code, but could also be in one of your 3rd party libraries.
Check your manifest to be sure, I guess you'll find something like
Import-Package:android.dalvik.
If that's the case you can test the bundle by manually removing that header and see if that helps. When you've got that clear, you can resolve it for example by making that import optional in bnd.
One of easy solution is:
Go to FuseESB console:
Type the command:
osgi:install mvn:commons-io/commons-io/2.1
Replace 'common's-io' with your your dependency's group id and artifact id (Maven)
e.g my dependency was:
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
Cheers
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.