View Full Version : Spring OSGI DM and Maven
growing
Jun 1st, 2008, 10:31 AM
hi,
I just created a spring-osgi bundle project using maven and eclipse. I also added some dependencies in pom.xml, and I found the m2eclipse plugin automatically added the jars to the reference library path. I can import the third party interface, class in my code. However, I can not add them in imported packages in MANIFEST.MF file. I mean I even can not find the expected interface or class in the selection dialog.
Some of the error message are following:
"No available bundle exports package 'org.springframework.orm.hibernate3.support'".
Can anybody help me?
Costin Leau
Jun 1st, 2008, 03:34 PM
Are you using PDE or something else?
Try using the Maven bnd plugin or just adding the packages by hand - this should be possible no matter what tool you're using.
growing
Jun 3rd, 2008, 08:40 AM
My enviroment is eclipse3.3 + m2eclipse. I also added the imported packages by hand, but the error information still showed.
Costin Leau
Jun 3rd, 2008, 10:32 AM
Again, are you using PDE? Where do you get the hibernate error in? Without contextual information is hard to make a guess on what goes wrong with your setup.
growing
Jun 3rd, 2008, 11:54 AM
I'm using PDE, but I also installed the m2eclipse plugin which contains the bnd maven plugin.
The error message displayed in the manifest.mf file. The file content are:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Common Plug-in
Bundle-SymbolicName: net.jianzi.eas.common
Bundle-Version: 1.0.0
Bundle-ClassPath: target/classes/
Bundle-Vendor: Jianzi Studio
Export-Package: net.jianzi.eas.common.dao.hibernate
Though I added the Import-Package statement by hand, the error information still displayed.
Costin Leau
Jun 4th, 2008, 04:09 AM
That's probably because the hibernate or spring-hibernate jar is unknown to PDE. See their help files - normally you have to create a profile and add all the dependencies in there so that PDE can understand what packages are present.
growing
Jun 4th, 2008, 08:39 AM
Maybe I should create a directory for PDE, and put all the required jar files into it. I also need to set the target platform to this directory through "preference" menu. However, why do I need maven, if I still need to do these finding, copying things for these required jar files by hand?
Costin Leau
Jun 5th, 2008, 01:23 AM
PDE has what it's called a Target Platform - indeed a folder with OSGi bundles. I haven't used it too much but you should be able to find more information from the Eclipse help.
The BND plugin (in maven) help with creating the imports automatically - they have a section on their web page on this topic - basically instead of you adding entries to the manifest when writing code, you simply let the tool do that for you.
Nico
Jun 5th, 2008, 03:34 AM
Hi,
I've just read this message which address the same kind of troubles I was mentioning in another thread.
I have the same problems that growing mentions, but this is not specific to hibernate or spring bundles. In fact m2eclipse works fine and add dependencies to the project classpath. The problem is that it seems that PDE is not able to look for Export-package in this referenced libraries. I've asked the question on m2eclipse maliing-list. Here is the answer (http://archive.m2eclipse.codehaus.org/user/2bb467fc0806040313t4e153bb4m468f0058f5648460%40mai l.gmail.com).
As Costin suggested, this works if you copy your dependencies to the eclipse target platform. May be you can use :
mvn eclipse:install-plugins
So what you can do is to :
create a target platform, possibly base on eclipse platform or RCP platform.
Configure eclipse to use this target platform : Preferences->Plugin-development->Target platform
run mvn eclipse:install-plugins (http://maven.apache.org/plugins/maven-eclipse-plugin/install-plugins-mojo.html) from your to copy all the dependencies to the target platform
Hope this helps.
growing
Jun 9th, 2008, 03:45 AM
Thanks all.
I also created and configurated the target platform successfully. However, after I runed the "mvn eclipse:install-plugins", it yet occurs an error belows:
Exception in thread "main" java.lang.NullPointerException
at org.apache.maven.plugin.eclipse.InstallPluginsMojo .install(InstallPluginsMojo.java:279)
at org.apache.maven.plugin.eclipse.InstallPluginsMojo .execute(InstallPluginsMojo.java:216)
at org.apache.maven.plugin.DefaultPluginManager.execu teMojo(DefaultPluginManager.java:579)
at org.apache.maven.lifecycle.DefaultLifecycleExecuto r.executeGoalAndHandleFailures(DefaultLifecycleExe cutor.java:498)
at org.apache.maven.lifecycle.DefaultLifecycleExecuto r.executeTaskSegmentForProject(DefaultLifecycleExe cutor.java:265)
at org.apache.maven.lifecycle.DefaultLifecycleExecuto r.executeTaskSegments(DefaultLifecycleExecutor.jav a:191)
at org.apache.maven.lifecycle.DefaultLifecycleExecuto r.execute(DefaultLifecycleExecutor.java:149)
at org.apache.maven.DefaultMaven.execute_aroundBody0( DefaultMaven.java:223)
at org.apache.maven.DefaultMaven.execute_aroundBody1$ advice(DefaultMaven.java:304)
at org.apache.maven.DefaultMaven.execute(DefaultMaven .java:1)
at org.apache.maven.embedder.MavenEmbedder.execute_ar oundBody2(MavenEmbedder.java:904)
at org.apache.maven.embedder.MavenEmbedder.execute_ar oundBody3$advice(MavenEmbedder.java:304)
at org.apache.maven.embedder.MavenEmbedder.execute(Ma venEmbedder.java:1)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java :176)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:6 3)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:5 2)
I checked the target platform directory, it has copied some libraries there.
Nico
Jun 9th, 2008, 04:13 AM
Hi,
For me mvn eclipse:install-plugins works fine.
I've look quickly InstallPluginsMojo.java (http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/InstallPluginsMojo.java?view=markup) source code. Line 279 deals with manifest file reading. May be you have a problem in your bundle MANIFEST or the one in a dependency library being copied.
growing
Jun 9th, 2008, 11:14 AM
Thanks Nico,
I have resolved this problem. Then command "mvn eclipse:install" need that all the dependencies jars are osgi bundle format, it means they should contain manifest.mf and the content are correct(such as Export-Package, Import-Package statement). I added the repository which be provided by this forum into pom.xml file, it can automatically download the pre-defined bundles.
I also found another question. When we using the m2eclipse eclipse plugin, it will add dependencies jar into the Maven Dependencies List in eclipse. It seems that we'll need not add the Import, Export statements in manifest.mf file anymore. We can use the package which belongs to other project or third-party jar file without importing the package in manifest.mf file.
Nico
Jun 9th, 2008, 01:34 PM
Hi,
As you said, when you add some dependency to your project's pom.xml, m2eclipse add the dependency jar to the maven dependency list. This means that the jar (which is located in your local maven repository) is added to your project compile classpath. If you enable workspace project resolution, and if you add another project of of your wokspace as a dependency, m2eclipse will add the referenced project into the list, not the installed jar. This is enough for compiling and indeed this does not require Import / Export directives.
Now, things are more complex when you develop OSGi bundles. OSGi requires that imported packages are declared in MANIFEST file, so eclipse will complain if you don't import packages you use. Eclipse looks for dependencies manifest to look for Exported package. Currently it can't look inside maven dependency. m2eclipse people are currntly working on this. That's why dependencies must be installed on the target platform (with mvn eclipse:install-plugins).
To be clear, when you develop OSGi bundles you must declare Import/Exopt. May be m2eclipse can (will) manage it automatically when adding pom.xml dependency. From my point of view and after spending some time on m2eclipse, i've decided to forget it and manage my dependency on my own.
Please note that this thread is not related to spring-dm anymore. Please see m2eclipse maling-lst for support on this product.
Hope this helps.
growing
Jun 18th, 2008, 09:08 AM
hi,
I'm very pleased with this news that m2eclipse team are currently working on how to automatically manage the import/export statement in manifest.mf file when using maven to importing dependency.
Since the maven is not only a dependency management tool, but also a good project assistant tool around development, test, deployment period. So, giving up it may be a sad thing, i think. It will be the best if we can find out the way which can resolve these problems.
Thanks for your advice.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.