I want to use cglib in an RCP client. The RCP client is build using maven and the tycho plugin. We are useing a manifest first strategy.
This is my MANIFEST.MF:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: INFO+ RCP Common UI Plug-in
Bundle-SymbolicName: a.company.prj.rcp.common.ui
Bundle-Version: 8.0.14.qualifier
Bundle-Vendor: Schweizerische Bundesbahnen SBB
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Bundle-Activator: a.company.prj.rcp.common.ui.CommonUIPlugin
Bundle-ActivationPolicy: lazy
Export-Package:
a.company.prj.rcp.common.ui,
...
a.company.prj.rcp.common.ui.wizards.page
Import-Package:
org.apache.log4j;version="1.2.17"
Require-Bundle:
org.eclipse.ui;bundle-version="3.7.0",
org.eclipse.ui.forms;bundle-version="3.5.101",
com.ibm.ws.jpa.thinclient;bundle-version="8.0.6",
...
a.company.prj.rcp.core;bundle-version="8.0.14",
...
To add cglib I changed the Import-Package section to:
Import-Package:
net.sf.cglib;version="3.2.0",
org.apache.log4j;version="1.2.17"
Now Eclipse complains with:
No available bundle exports package 'net.sf.cglib'
Ayn ideas how to include cglib with this environment?
You will need to add the cglib bundle to your target platform, i.e., the set of all bundles Tycho will consider when resolving dependencies. You have three options to do so (taken from the Tycho wiki page on this topic):
You can simply add an entire p2 repository to your target platform.
You can use a .target file and reference the cglib bundle therein (as already suggested by stempler).
You can declare a Maven <dependency> on cglib and make Tycho “consider” it.
As you already have a working Tycho build, I suggest you use whatever option you or your colleagues have used in the build before.
One more note: Options 1 and 2 require that the cglib bundle is available in a p2 repository, whereas option 3 works even if the bundle comes from a “normal” Maven repository like the Central Repository. But in all three cases the cglib JAR must be a valid OSGi bundle, i.e., include an OSGi MANIFEST.MF with Bundle-SymbolicName etc.
You should build the cglib jar file to a plugin and install it in Eclipse before you can use it. You can refer to this link: How can I add the external jar to the eclipse rcp application?
Related
What is the purpose to use Maven Tycho plugins. I read here tycho is used for building eclipse plugins and OSGI bundle.
Questions:- Can not we build eclipse plugins and OSGI bundle just by using the plain old maven POM.xml file[by not using tycho plugin].
What does maven need tycho plugin to help it build eclipse plugin and OSGI bundles?
Why should we use Maven tycho plugin to build eclipse plugins and OSGI bundles?
When using maven (or other command line build tools) manifest.mf) in combination with Eclipse (or another IDE) the classpath ends up being written down twice - once in the pom.xml and once in the Eclipse .classpath (or, for OSGi, in the target platform and manifest.mf). This violates the DRY principle.
There are various solutions to this problem. One is something like m2e, where you use the pom.xml to generate the Eclipse .classpath. Alternatively, you can go in the other direction and start by getting things compiling in Eclipse, and then use a maven plugin to convert that Eclipse setup to a maven build. This is what Tycho does, with the extra wrinkle that it works from a PDE manifest + target platform rather than directly from the .classpath.
Maven doesn't have a built-in packaging type for OSGi bundles and/or Eclipse plugins. So unless you want to use the jar packaging type and manually add OSGi specifics, you need a Maven plug-in to help you with this.
Tycho is one of the plugins that add support for building OSGi bundles.
I know that when creating an OSGI Bundle I can declare that it needs other bundles to work correctly (in this situation other bundles need to export things that I will import in mentioned bundle).
But what if I need a jar file for a bundle to work?
Is it possible to write this information in MANIFEST.MF? I have the bundle and for some legacy reasons of other bundles that are used my bundle requires usage of a few jar files.
For building this bundle I use maven plugin for creating OSGI bundles (maven-bundle-plugin).
You cannot use normal JARs as dependency of a bundle. You can use only bundles (JARs with OSGI maniifest) as the dependency of a bundle.
You have the following options:
you embedd such jars into your bundle (http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html chapter titled "Embedding dependencies"). This means that that JAR will be inside your bundle, and the manifest will instruct the OSGI container to load the classes from that JAR as well.
try to find the OSGI version of your dependency jar. You can give a try to Spring EBR or to ServiceMix bundles
you create a bundle for each such jar with embedding (1. point) and then you add them as imported package or required bundle (imported package should be favoured).
I would prefer the second point, if not found, then the third.
I have an OSGi bundle and I'm using java mail api in it to add mail functionality.
The problem I'm facing is, the bundle class loader is not adding the entries for mail-1.4.jar and activation.jar in classpath variable which it creates while loading the local or global classes.
I've added the mail-1.4.jar and activation.jar in the bundle classpath in manifest and these jar are simple jars(not the OSGi bundles). And these are in lib directory in my bundle.
Now while loading javax.mail.Address class ClassNotFoundException is thrown.
And this is when I'm running my application using command line.
It works completely fine when I run it in Eclipse.
I'm using equinox as my container.
Any suggestions?
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Workexp
Bundle-SymbolicName: com.gslab.workexp
Bundle-Version: 1.0.0
Bundle-Activator: com.gslab.workexp.Activator
Bundle-Vendor: GSLAB
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Import-Package: org.osgi.framework
Bundle-ClassPath: .,
lib/mysql-connector-java-5.1.20-bin.jar,
lib/commons-beanutils-1.8.0.jar,
lib/commons-collections-2.1.1.jar,
lib/commons-digester-2.1.jar,
lib/commons-javaflow-20060411.jar,
lib/commons-logging-1.1.1.jar,
lib/iText-2.1.7.jar,
lib/jasperreports-4.6.0.jar,
lib/jdt-compiler-3.1.1.jar,
lib/log4j-1.2.9.jar,
lib/mail-1.4.jar,
lib/activation.jar
Your use of the bundle classpath is unusual. You should use Import-Package (best practice) or Require-Bundle for dependencies. Bundle classpath is saying all those jars are packaged inside a lib folder inside your bundle archive. I suspect this isn't the case, and even if it was, you'd be totally bypassing all the modularity Eclipse gives you.
Try adding the 'javax.mail' package to your Import-Package header. For an explanation of why this isn't needed in Eclipse, see i/Why_does_Eclipse_find_javax.swing_but_not_Felix%3F.
Make sure you have included your lib folder inside the bin.includes (Build Tab in the Manifest editor) or they won't get exported in the final jar.
This is a very annoying 'bug' that it works in eclipse (because the files are accessible in the file system) but the builder will ignore not included files.
We have an OSGi project which needs spring and hibernate capability. I tried adding them separately as bundles, but they are not visible to the runtime environment. Below is a screenshot of our project (better picture http://i.stack.imgur.com/d6gV9.png). In the picture the plugins start with spring and hibernate contain the jars and I added them to the import packages in the needed bundles. I'm also attaching a sample manifest with this. Any help is appreciated. I always get classnotfoundexceptions for spring classes.
I created the jar bundles using eclipse's create plugin fro archives. In the wizard I selected them to be standard OSGi plugins (not sure if that is the right way). I'm building the project through IBM RAD (Aries).
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: org.xxx.scar.web1
Bundle-SymbolicName: org.xxx.scar.web1
Bundle-Version: 1.0.0.qualifier
Bundle-ClassPath: WEB-INF/classes
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Web-ContextPath: /org.frb.scar.web1
Import-Package: javax.el;version="2.0";resolution:=optional,
javax.faces,
javax.faces.application,
javax.faces.component,
javax.faces.component.html,
javax.faces.context,
javax.faces.convert,
javax.faces.el,
javax.faces.event,
javax.faces.lifecycle,
javax.faces.model,
javax.faces.render,
javax.faces.validator,
javax.faces.webapp,
javax.servlet;version="2.5",
javax.servlet.annotation;resolution:=optional,
javax.servlet.http;version="2.5",
javax.servlet.jsp;version="2.0",
javax.servlet.jsp.el;version="2.0",
javax.servlet.jsp.tagext;version="2.0",
org.frb.scar.entity,
org.frb.scar.manager,
org.frb.scar.services,
org.frb.scar.utils,
org.springframework.beans,
org.springframework.beans.annotation,
org.springframework.beans.factory,
org.springframework.beans.factory.access,
org.springframework.beans.factory.access.el,
org.springframework.beans.factory.annotation,
org.springframework.beans.factory.config,
org.springframework.beans.factory.parsing,
org.springframework.beans.factory.serviceloader,
org.springframework.beans.factory.support,
org.springframework.beans.factory.wiring,
org.springframework.beans.factory.xml,
org.springframework.beans.propertyeditors,
org.springframework.beans.support
and more spring jars, until web.
Error
java.lang.ClassNotFoundException: org.springframework.web.context.request.RequestContextListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
and many....
Thanks,
Bab.
The answer is in the error message: ClassNotFoundException: org.springframework.web.context.request.RequestContextListener.
Package org.springframework.web.context.request is not listed in the imports of your bundle.
I have a Vaadin application, which I'm trying to build as a set of OSGI bundles using Maven + BND.
I can't deploy the bundles To Apache Felix because some dependencies can't be resolved.
Apache Felix complains that can't find package XYZ required by bundle "A", although this package is defined in this same bundle!!
I looked at the MANIFEST.MF file generated by Maven + BND and saw that the package (XYZ) from this bundle is added to both "import" and "export" sections. I understand why "export", but why "import"?? Why is the bundle trying to import its own package?
my MANIFEST.MF
Manifest-Version: 1.0
Export-Package: myexample.admin;uses:="com.vaadin.ui,myexample.webshared,
com.vaadin.terminal,myexample.mvc.view.impl,
myexample.mvc.model,myexample.mvc.renderer.map.impl,
myexample.mvc.renderer,myexample.mvc.model.impl,myexample.util"
Built-By: ask
Tool: Bnd-0.0.384
Bundle-Name: admin
Created-By: 1.6.0_21 (Sun Microsystems Inc.)
Bundle-Version: 0
Build-Jdk: 1.6.0_26
Bnd-LastModified: 1315674240833
Bundle-ManifestVersion: 2
Import-Package: myexample.admin;version="1.0",myexample.mvc.model,
myexample.mvc.model.impl,myexample.mvc.renderer,
myexample.mvc.renderer.map.impl,myexample.mvc.view.impl,
myexample.util,myexample.webshared,com.vaadin.terminal,com.vaadin.ui
Bundle-SymbolicName: admin
Include-Resource: ..\classes
Originally-Created-By: Apache Maven Bundle Plugin
This is correct behaviour. The explanation is in section 3.5.6 of the OSGi core specification.
Regarding the unresolved error from Felix... this must be related to something else. Please post the actual error message.
Niel is, of course correct. To be honest though, I've been very successful with using the noimports:=true to get around this. In my applications, I usually have the following in my maven-bundle-plugin section:
<Export-package>*;noimports:=true</export-package>
This results in all of your packages being exported into OSGi, and none of them will appear in your import-package section. If you only need a couple of your exported packages to not appear in your import-package section, you can set the noimports flag for each individual package. Lastly, this syntax is from BND, so it should also work in your .bnd files.