You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Dan H <hu...@yahoo.de> on 2010/04/05 02:01:46 UTC

Embedding Hibernate in an OSGi bundle using maven-bundle-plugin is hard

Has anyone managed to embed Hibernate within their bundle using Maven
and maven-bundle-plugin? I'm getting errors that seem to be the result
of bad manifest "Import-Package" sections:

----
ERROR: Error starting file:/C:/dev/felix/bundle/kurt-handler-a-1.0.0.jar
(org.osgi.framework.BundleException: Unresolved
 constraint in bundle de.huss.kurt-handler-a [2]: package;
(package=com.sun.jdmk.comm))
org.osgi.framework.BundleException: Unresolved constraint in bundle
de.huss.kurt-handler-a [2]: package; (package=com.su
n.jdmk.comm)
        at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3295)
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1653)
        at
org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1124)
        at
org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
        at java.lang.Thread.run(Thread.java:619)
----

There is a lot of guesswork involved, but I think that the bundle plugin
does not handle the <exclusions> node of a dependency and adds a package
import to the manifest anyway. It also seems possible to me that the
bundle plugin is adding imports for dependencies that are flagged as
optional. I've attached the pom.xml and the generated manifest for those
who care.

Another thought: maybe I'm missing some magic Maven artifact that I
could import to get a working Hibernate library for OSGi environments?

Thank you very much in advance!
-Dan

Re: Embedding Hibernate in an OSGi bundle using maven-bundle-plugin is hard

Posted by Dan H <hu...@yahoo.de>.

-------- Original Message  --------
Subject: Re: Embedding Hibernate in an OSGi bundle using
maven-bundle-plugin 	is hard
From: Guillaume Nodet <gn...@gmail.com>
To: users@felix.apache.org
Date: 06.04.2010 16:47

> Is there any reason why you want to embed hibernate instead of using it as a
> real bundle ?

I was expecting that having Maven manage all dependencies including
dependencies on other bundles would be possible. However, I couldn't
find any artifacts that would just let me do this:

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core-osgi</artifactId>
			<version>3.3.2</version>
			<scope>provided</scope>
		</dependency>

So embedding the existing artifacts seemed to be the next best solution.

> Also the problem isn't really maven i think, as whichever tool you use,
> you'll have to write the manifest somehow.

I agree, there's nothing wrong with Maven. But I'm a lazy bastard. Was
kind of hoping for maven-bundle-plugin to provide a 1:1 mapping: Maven
artifact ----> OSGi bundle. The thought of not ever having to touch that
manifest seemed appealing.

> Instead of going that way, I would do the following:
>    * mark all imports as optional
>    * deploy your bundles
>    * check which packages are actually needed by deploying dependencies
> until things work
>    * mark the imports from these dependencies as mandatory
> This is not really clean, but I don't see what else you can do if you don't
> want to use the existing hibernate bundles.
> 

Clean sounds good. I'd rather do everything by hand than have anything
in my pom/manifest that isn't self-explanatory.

I was able to install a hibernate bundle from
http://osgi-hibernate.googlecode.com but I couldn't find a way to turn
it into a Maven artifact. Am I missing something?

-Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Embedding Hibernate in an OSGi bundle using maven-bundle-plugin is hard

Posted by Guillaume Nodet <gn...@gmail.com>.
Is there any reason why you want to embed hibernate instead of using it as a
real bundle ?
Also the problem isn't really maven i think, as whichever tool you use,
you'll have to write the manifest somehow.
Instead of going that way, I would do the following:
   * mark all imports as optional
   * deploy your bundles
   * check which packages are actually needed by deploying dependencies
until things work
   * mark the imports from these dependencies as mandatory
This is not really clean, but I don't see what else you can do if you don't
want to use the existing hibernate bundles.

On Tue, Apr 6, 2010 at 16:41, Dan H <hu...@yahoo.de> wrote:

> Just found out that a similar issue has already been addressed here:
> http://issues.apache.org/jira/browse/FELIX-954
>
> I checked out the current trunk, only to find out that the problem
> remains. Looking at the code was very helpful, I now suspect that the
> problem is actually caused by a cyclic dependency that causes
> MavenProject.getArtifacts() to return an incomplete (?) collection in
> BundlePlugin.getEmbeddableArtifacts().
>
> The cycle exists in dom4j-1.6.1 which depends on dom4j-1.5.2 which
> depends on jaxen1.1-beta which depends on dom4j-1.5.2 (see
> http://jira.codehaus.org/browse/MNG-1944)
>
> This is backed up by the dependency plugin which states:
> [INFO] The following files have been resolved:
> [INFO]    antlr:antlr:jar:2.7.6:compile
> [INFO]    c3p0:c3p0:jar:0.9.1:compile
> [INFO]    cglib:cglib:jar:2.1.3:compile
> [INFO]    commons-collections:commons-collections:jar:3.1:compile
> [INFO]    de.huss:kurt:jar:1.0.0:provided
> [INFO]    dom4j:dom4j:jar:1.6.1:compile
> [INFO]    javax.transaction:jta:jar:1.1:compile
> [INFO]    junit:junit:jar:4.6:test
> [INFO]    mysql:mysql-connector-java:jar:5.1.12:compile
> [INFO]    org.apache.felix:javax.servlet:jar:1.0.0:provided
> [INFO]    org.apache.felix:org.osgi.compendium:jar:1.4.0:provided
> [INFO]    org.apache.felix:org.osgi.core:jar:1.4.0:provided
> [INFO]    org.apache.felix:org.osgi.foundation:jar:1.2.0:provided
> [INFO]    org.hibernate:hibernate-c3p0:jar:3.3.2.GA:compile
> [INFO]    org.hibernate:hibernate-core:jar:3.3.2.GA:compile
> [INFO]    org.slf4j:slf4j-api:jar:1.5.8:compile
> [INFO]    xml-apis:xml-apis:jar:1.0.b2:compile
>
> All of the dom4j dependencies are missing.
>
> I assume it is not easily possible to detect this situation since no
> exception appears to be thrown by MavenProject.getArtifacts() when a
> cyclic dependency stops the resolve process.
>
> Anyway, I'm giving up on Maven integration. Thanks again for all your help.
>
> -Dan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Blog: http://gnodet.blogspot.com/
------------------------
Open Source SOA
http://fusesource.com

Re: Embedding Hibernate in an OSGi bundle using maven-bundle-plugin is hard

Posted by Dan H <hu...@yahoo.de>.
Just found out that a similar issue has already been addressed here:
http://issues.apache.org/jira/browse/FELIX-954

I checked out the current trunk, only to find out that the problem
remains. Looking at the code was very helpful, I now suspect that the
problem is actually caused by a cyclic dependency that causes
MavenProject.getArtifacts() to return an incomplete (?) collection in
BundlePlugin.getEmbeddableArtifacts().

The cycle exists in dom4j-1.6.1 which depends on dom4j-1.5.2 which
depends on jaxen1.1-beta which depends on dom4j-1.5.2 (see
http://jira.codehaus.org/browse/MNG-1944)

This is backed up by the dependency plugin which states:
[INFO] The following files have been resolved:
[INFO]    antlr:antlr:jar:2.7.6:compile
[INFO]    c3p0:c3p0:jar:0.9.1:compile
[INFO]    cglib:cglib:jar:2.1.3:compile
[INFO]    commons-collections:commons-collections:jar:3.1:compile
[INFO]    de.huss:kurt:jar:1.0.0:provided
[INFO]    dom4j:dom4j:jar:1.6.1:compile
[INFO]    javax.transaction:jta:jar:1.1:compile
[INFO]    junit:junit:jar:4.6:test
[INFO]    mysql:mysql-connector-java:jar:5.1.12:compile
[INFO]    org.apache.felix:javax.servlet:jar:1.0.0:provided
[INFO]    org.apache.felix:org.osgi.compendium:jar:1.4.0:provided
[INFO]    org.apache.felix:org.osgi.core:jar:1.4.0:provided
[INFO]    org.apache.felix:org.osgi.foundation:jar:1.2.0:provided
[INFO]    org.hibernate:hibernate-c3p0:jar:3.3.2.GA:compile
[INFO]    org.hibernate:hibernate-core:jar:3.3.2.GA:compile
[INFO]    org.slf4j:slf4j-api:jar:1.5.8:compile
[INFO]    xml-apis:xml-apis:jar:1.0.b2:compile

All of the dom4j dependencies are missing.

I assume it is not easily possible to detect this situation since no
exception appears to be thrown by MavenProject.getArtifacts() when a
cyclic dependency stops the resolve process.

Anyway, I'm giving up on Maven integration. Thanks again for all your help.

-Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Embedding Hibernate in an OSGi bundle using maven-bundle-plugin is hard

Posted by Justin Edelson <ju...@gmail.com>.
On 4/5/10 11:10 AM, Dan H wrote:
> 
>>
>>
>> On 4/4/10 8:01 PM, Dan H wrote:
>>> Has anyone managed to embed Hibernate within their bundle using Maven
>>> and maven-bundle-plugin? I'm getting errors that seem to be the result
>>> of bad manifest "Import-Package" sections:
>>>
>>> ----
>>> ERROR: Error starting file:/C:/dev/felix/bundle/kurt-handler-a-1.0.0.jar
>>> (org.osgi.framework.BundleException: Unresolved
>>>   constraint in bundle de.huss.kurt-handler-a [2]: package;
>>> (package=com.sun.jdmk.comm))
>>> org.osgi.framework.BundleException: Unresolved constraint in bundle
>>> de.huss.kurt-handler-a [2]: package; (package=com.su
>>> n.jdmk.comm)
>>>          at
>>> org.apache.felix.framework.Felix.resolveBundle(Felix.java:3295)
>>>          at org.apache.felix.framework.Felix.startBundle(Felix.java:1653)
>>>          at
>>> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1124)
>>>          at
>>> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
>>>          at java.lang.Thread.run(Thread.java:619)
>>> ----
>>>
>>> There is a lot of guesswork involved, but I think that the bundle plugin
>>> does not handle the<exclusions>  node of a dependency and adds a package
>>> import to the manifest anyway. It also seems possible to me that the
>>> bundle plugin is adding imports for dependencies that are flagged as
>>> optional. I've attached the pom.xml and the generated manifest for those
>>> who care.
>>>    
>>
>> Well, if you don't need that package, try adding this to the
>> maven-bundle-plugin configuration:
>>
>> <Import-Package>!com.sun.jdmk.*,*</Import-Package>
>>
>> This will exclude jdmk and all subpackages from your imports, but still
>> import everything else.
>>
> Yeah, that's what I did for the first four imports: jdmk, javassist,
> org.jaxen.pattern, org.apache.commons.logging, etc. etc.
> 
> However, I realized that this trial&error approach throws us back to
> manual (non-)dependency management: having to make a list of all things
>  that we *don't* want to be imported doesn't really solve the problem.
It's ultimately very difficult, if not impossible, for someone
repackaging a JAR to know what imports are required and which are optional.

AFAIK, commons-logging is required for Hibernate as is javassist. Take a
look at the manifest of the SpringSource packaged Hibernate:
http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.org.hibernate&version=3.2.6.ga

> 
> Well, instead of crying in your face I'm going to try make myself
> useful. I'll take a look at the plugin code. Perhaps I can hack
> something in that makes this fantastic plugin it do its job as
> advertised :-)

Best of luck, but I think your time would be better spent articulating
to the Hibernate team why they need to provide proper OSGi bundles. The
plugin can be improved for sure, but you shouldn't need to embed
Hibernate in your bundle in the first place IMHO.

Justin

> 
> To those who found this email when googling "Maven Hibernate OSGi" or
> something like that: if I ever find a solution, I'll make sure to post
> it here.
> 
> -Dan
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Embedding Hibernate in an OSGi bundle using maven-bundle-plugin is hard

Posted by Dan H <hu...@yahoo.de>.
> 
> 
> On 4/4/10 8:01 PM, Dan H wrote:
>> Has anyone managed to embed Hibernate within their bundle using Maven
>> and maven-bundle-plugin? I'm getting errors that seem to be the result
>> of bad manifest "Import-Package" sections:
>>
>> ----
>> ERROR: Error starting file:/C:/dev/felix/bundle/kurt-handler-a-1.0.0.jar
>> (org.osgi.framework.BundleException: Unresolved
>>   constraint in bundle de.huss.kurt-handler-a [2]: package;
>> (package=com.sun.jdmk.comm))
>> org.osgi.framework.BundleException: Unresolved constraint in bundle
>> de.huss.kurt-handler-a [2]: package; (package=com.su
>> n.jdmk.comm)
>>          at
>> org.apache.felix.framework.Felix.resolveBundle(Felix.java:3295)
>>          at org.apache.felix.framework.Felix.startBundle(Felix.java:1653)
>>          at
>> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1124)
>>          at
>> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
>>          at java.lang.Thread.run(Thread.java:619)
>> ----
>>
>> There is a lot of guesswork involved, but I think that the bundle plugin
>> does not handle the<exclusions>  node of a dependency and adds a package
>> import to the manifest anyway. It also seems possible to me that the
>> bundle plugin is adding imports for dependencies that are flagged as
>> optional. I've attached the pom.xml and the generated manifest for those
>> who care.
>>    
> 
> Well, if you don't need that package, try adding this to the
> maven-bundle-plugin configuration:
> 
> <Import-Package>!com.sun.jdmk.*,*</Import-Package>
> 
> This will exclude jdmk and all subpackages from your imports, but still
> import everything else.
> 
Yeah, that's what I did for the first four imports: jdmk, javassist,
org.jaxen.pattern, org.apache.commons.logging, etc. etc.

However, I realized that this trial&error approach throws us back to
manual (non-)dependency management: having to make a list of all things
 that we *don't* want to be imported doesn't really solve the problem.

Well, instead of crying in your face I'm going to try make myself
useful. I'll take a look at the plugin code. Perhaps I can hack
something in that makes this fantastic plugin it do its job as
advertised :-)

To those who found this email when googling "Maven Hibernate OSGi" or
something like that: if I ever find a solution, I'll make sure to post
it here.

-Dan

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org


Re: Embedding Hibernate in an OSGi bundle using maven-bundle-plugin is hard

Posted by "Richard S. Hall" <he...@ungoverned.org>.

On 4/4/10 8:01 PM, Dan H wrote:
> Has anyone managed to embed Hibernate within their bundle using Maven
> and maven-bundle-plugin? I'm getting errors that seem to be the result
> of bad manifest "Import-Package" sections:
>
> ----
> ERROR: Error starting file:/C:/dev/felix/bundle/kurt-handler-a-1.0.0.jar
> (org.osgi.framework.BundleException: Unresolved
>   constraint in bundle de.huss.kurt-handler-a [2]: package;
> (package=com.sun.jdmk.comm))
> org.osgi.framework.BundleException: Unresolved constraint in bundle
> de.huss.kurt-handler-a [2]: package; (package=com.su
> n.jdmk.comm)
>          at org.apache.felix.framework.Felix.resolveBundle(Felix.java:3295)
>          at org.apache.felix.framework.Felix.startBundle(Felix.java:1653)
>          at
> org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1124)
>          at
> org.apache.felix.framework.StartLevelImpl.run(StartLevelImpl.java:264)
>          at java.lang.Thread.run(Thread.java:619)
> ----
>
> There is a lot of guesswork involved, but I think that the bundle plugin
> does not handle the<exclusions>  node of a dependency and adds a package
> import to the manifest anyway. It also seems possible to me that the
> bundle plugin is adding imports for dependencies that are flagged as
> optional. I've attached the pom.xml and the generated manifest for those
> who care.
>    

Well, if you don't need that package, try adding this to the 
maven-bundle-plugin configuration:

<Import-Package>!com.sun.jdmk.*,*</Import-Package>

This will exclude jdmk and all subpackages from your imports, but still 
import everything else.

-> richard

> Another thought: maybe I'm missing some magic Maven artifact that I
> could import to get a working Hibernate library for OSGi environments?
>
> Thank you very much in advance!
> -Dan
>    
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org