You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@sling.apache.org by Federico Paparoni <fe...@gmail.com> on 2010/06/22 15:33:47 UTC

JAR dependency for a bundle

Hi all,

I'm creating a new bundle to test a servlet that manage a new extension.
I have dependency with iText and, obviously, when I try to deploy the bundle
I receive this error in log

22.06.2010 15:24:39.549 *ERROR* [Background Update david (64)]
org.apache.felix.http.jetty %bundles.pluginTitle: Cannot install or update
bu
ndle from C:\DOCUME~1\a155876\IMPOST~1\Temp\install8737651860335814136.tmp
(org.osgi.framework.BundleException: Unresolved constraint in bun
dle david [64]: package; (package=com.itextpdf.text.pdf))
org.osgi.framework.BundleException: Unresolved constraint in bundle david
[64]: pa
ckage; (package=com.itextpdf.text.pdf)
        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.updateBundle(Felix.java:2004)
        at org.apache.felix.framework.BundleImpl.update(BundleImpl.java:923)
        at
org.apache.felix.webconsole.internal.core.UpdateHelper.doRun(UpdateHelper.java:60)
        at
org.apache.felix.webconsole.internal.core.BaseUpdateInstallHelper.doRun(BaseUpdateInstallHelper.java:89)
        at
org.apache.felix.webconsole.internal.core.UpdateHelper.doRun(UpdateHelper.java:70)
        at
org.apache.felix.webconsole.internal.core.BaseUpdateInstallHelper.run(BaseUpdateInstallHelper.java:121)
        at java.lang.Thread.run(Unknown Source)

What are the best practises in that case? Where I have to put the dependency
JAR?
Cheers

-- 
Federico

Re: JAR dependency for a bundle

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Wed, Jun 23, 2010 at 10:32 AM, Vidar Ramdal <vi...@idium.no> wrote:
> ...I usually prefer these annotations, because you can easily use Java
> constants as values, making refactoring easier. Also, IDE support is
> much better....

Absolutely agree, thanks Vidar for mentioning this!
-Bertrand

Re: JAR dependency for a bundle

Posted by Vidar Ramdal <vi...@idium.no>.
> Hi,
>
> On Tue, Jun 22, 2010 at 11:35 PM, Federico Paparoni
> <fe...@gmail.com> wrote:
>> ...the installation is ok, but
>> the servlet isn't registered..,,
>>
>> http://code.google.com/p/davidgsoc2010/source/browse/trunk/src/main/java/sling/gsoc/david/servlet/PdfExtension.java

On Wed, Jun 23, 2010 at 12:10 AM, Bertrand Delacretaz
<bd...@apache.org> wrote:
> Weird problem - you had two comment blocks before the servlet class,
> so the first block with @scr javadoc tags is ignored.
>
> With the patch below, your servlet works for me, handling .pdf extensions.
> [...]

Federico, maybe you already know, but you could also use 'real' Java
annotations instead of the ones embedded in Javadocs. The javadoc
annotation parser has some weird issues with it (as you obviusly has
seen).

See http://felix.apache.org/site/apache-felix-maven-scr-plugin.html
for more on the annotations.

In short, what you do is replace /** scr.component **/ with @Component
(not wrapped in comments), /** scr.property **/ with @Property and so
on.

I usually prefer these annotations, because you can easily use Java
constants as values, making refactoring easier. Also, IDE support is
much better.

Note that you cannot mix old-style and new-style annotations in the same file.

-- 
Vidar S. Ramdal <vi...@idium.no> - http://www.idium.no
Sommerrogata 13-15, N-0255 Oslo, Norway
+ 47 22 00 84 00 / +47 22 00 84 76
Quando omni flunkus moritatus!

Re: JAR dependency for a bundle

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Jun 22, 2010 at 11:35 PM, Federico Paparoni
<fe...@gmail.com> wrote:
> ...the installation is ok, but
> the servlet isn't registered..,,
>
> http://code.google.com/p/davidgsoc2010/source/browse/trunk/src/main/java/sling/gsoc/david/servlet/PdfExtension.java

Weird problem - you had two comment blocks before the servlet class,
so the first block with @scr javadoc tags is ignored.

With the patch below, your servlet works for me, handling .pdf extensions.

-Bertrand

Index: src/main/java/sling/gsoc/david/servlet/PdfExtension.java
===================================================================
--- src/main/java/sling/gsoc/david/servlet/PdfExtension.java	(revision 20)
+++ src/main/java/sling/gsoc/david/servlet/PdfExtension.java	(working copy)
@@ -22,13 +22,10 @@
  *               value="sling/servlet/default"
  *
  * @scr.property name="sling.servlet.methods"
- *               values.0="GET"
- *               values.1="POST"
+ *               values.1="GET"
  *
  * @scr.property name="sling.servlet.extensions"
  *               value = "pdf"
- */
-/**
  *
  * @author Federico Paparoni
  */

Re: JAR dependency for a bundle

Posted by Federico Paparoni <fe...@gmail.com>.
Hi,

2010/6/22 Bertrand Delacretaz <bd...@apache.org>

> Hi,
>
> On Tue, Jun 22, 2010 at 5:04 PM, Federico Paparoni
> <fe...@gmail.com> wrote:
> > ...The configuration of the servlet looks like this
> >
> > /** Sling Servlet registered with PDF extensions
> >  *
> >  * @scr.component immediate="true" metatype="no"
> >  * @scr.service interface="javax.servlet.Servlet"
> >  *
> >  * @scr.property name="service.description" value="PDF Extension Servlet"
> >  * @scr.property name="service.vendor" value="David Mini CMS"
> >  *
> >  * @scr.property name="sling.servlet.resourceTypes"
> >  *               value="sling/servlet/default"
> >  *
> >  * @scr.property name="sling.servlet.extensions"
> >  *               value = "pdf"
> >  */
>
> At first sight this looks good to me, you can also compare with test
> servlets found under
> http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/
>
>
I didn't find a complete example about an additional extension, only
integration test servlets. Is there something like this?


> >...when I call in the browser I
> > see this error
> >
> >...
> > TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0}
> > 0 (2010-06-22 16:57:55) LOG No renderer for extension pdf
> > 0 (2010-06-22 16:57:55) TIMER_START{handleError:status=404}
> >
> > Am I missing something to correctly handle the request?
>
> The DefaultGetServlet is called instead of your servlet - did you
> check that your servlet is started? It should be present in the
> "components" pane of the OSGi console.
>
>
There isn't the servlet in this panel. Anyway the installation is ok, but
the servlet isn't registered.
As I said, I only wrote the annotations in the servlet

http://code.google.com/p/davidgsoc2010/source/browse/trunk/src/main/java/sling/gsoc/david/servlet/PdfExtension.java


Nothing else to setup?

-- 
Federico

Re: JAR dependency for a bundle

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi,

On Tue, Jun 22, 2010 at 5:04 PM, Federico Paparoni
<fe...@gmail.com> wrote:
> ...The configuration of the servlet looks like this
>
> /** Sling Servlet registered with PDF extensions
>  *
>  * @scr.component immediate="true" metatype="no"
>  * @scr.service interface="javax.servlet.Servlet"
>  *
>  * @scr.property name="service.description" value="PDF Extension Servlet"
>  * @scr.property name="service.vendor" value="David Mini CMS"
>  *
>  * @scr.property name="sling.servlet.resourceTypes"
>  *               value="sling/servlet/default"
>  *
>  * @scr.property name="sling.servlet.extensions"
>  *               value = "pdf"
>  */

At first sight this looks good to me, you can also compare with test
servlets found under
http://svn.apache.org/repos/asf/sling/trunk/launchpad/integration-tests/

>...when I call in the browser I
> see this error
>
>...
> TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0}
> 0 (2010-06-22 16:57:55) LOG No renderer for extension pdf
> 0 (2010-06-22 16:57:55) TIMER_START{handleError:status=404}
>
> Am I missing something to correctly handle the request?

The DefaultGetServlet is called instead of your servlet - did you
check that your servlet is started? It should be present in the
"components" pane of the OSGi console.

-Bertrand

Re: JAR dependency for a bundle

Posted by Federico Paparoni <fe...@gmail.com>.
2010/6/22 Justin Edelson <ju...@gmail.com>

> On 6/22/10 10:06 AM, Bertrand Delacretaz wrote:
> > Hi Federico,
> >
> > On Tue, Jun 22, 2010 at 3:33 PM, Federico Paparoni
> > <fe...@gmail.com> wrote:
> >> I'm creating a new bundle to test a servlet that manage a new extension.
> >> I have dependency with iText and, obviously, when I try to deploy the
> bundle
> >> I receive this error in log
> >>
> >> ...(org.osgi.framework.BundleException: Unresolved constraint in bun
> >> dle david [64]: package; (package=com.itextpdf.text.pdf))
> >
> >> ... What are the best practises in that case? Where I have to put the
> dependency
> >> JAR?...
> >
> > Best is to find an OSGi bundle that exports the required iText
> > classes. Many Apache projects (like commons.a.o) now include the OSGi
> > metadata in their standard jars, so you can just load them as bundles.
> >
> > I don't know if that's the case for iText, searching "itext osgi
> > bundle" on google should help find out if such bundles are available.
> > Install the bundle (using OSGi console is the easiest for a quick
> > test) , and check the OSGi console to see if it exports the packages
> > that you need.
> FWIW, there is bundle for iText in the SpringSource bundle repository:
>
> http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.lowagie.text&version=2.0.8
>
> Justin
>
> >
> > If you cannot find an iText bundle, you could "OSGify" an existing
> > iText jar using the bnd tool or the maven-bundle-plugin to add the
> > required MANIFEST.MF information to it.
> >
> > Last (and least optimal) solution is to embed the iText classes in
> > your bundle using the Embed-Dependency option of the
> > maven-bundle-plugin, see
> > http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
> >
> > That last option might be the easiest for a quick test, the problem is
> > that it adds bloat to your bundle and if another bundle needs those
> > classes that would lead to duplication.
> >
> > Hope this helps,
> > -Bertrand
>
>
That's ok. Now I simply modify the pom using the worst method,
Embed-Dependency, and I receive no error.
Later I will create a bundle for iText (thanks Justin but I'm using a
different version).
I receive no error, but the Servlet isn't called for the extension .pdf.
The configuration of the servlet looks like this

/** Sling Servlet registered with PDF extensions
 *
 * @scr.component immediate="true" metatype="no"
 * @scr.service interface="javax.servlet.Servlet"
 *
 * @scr.property name="service.description" value="PDF Extension Servlet"
 * @scr.property name="service.vendor" value="David Mini CMS"
 *
 * @scr.property name="sling.servlet.resourceTypes"
 *               value="sling/servlet/default"
 *
 * @scr.property name="sling.servlet.extensions"
 *               value = "pdf"
 */

The servlet extends SlingAllMethodsServlet and in the doGet method I create
a simple pdf rappresentation of the node. But when I call in the browser I
see this error

0 (2010-06-22 16:57:55) LOG Method=GET, PathInfo=/content/david/_your_title_.pdf
0 (2010-06-22 16:57:55) TIMER_START{ResourceResolution}
0 (2010-06-22 16:57:55) TIMER_END{0,ResourceResolution}
URI=/content/david/_your_title_.pdf resolves to
Resource=JcrNodeResource, type=david, superType=null,
path=/content/david/_your_title_
0 (2010-06-22 16:57:55) LOG Resource Path Info: SlingRequestPathInfo:
path='/content/david/_your_title_', selectorString='null',
extension='pdf', suffix='null'
0 (2010-06-22 16:57:55) TIMER_START{ServletResolution}
0 (2010-06-22 16:57:55) TIMER_START{resolveServlet(JcrNodeResource,
type=david, superType=null, path=/content/david/_your_title_)}
0 (2010-06-22 16:57:55) TIMER_END{0,resolveServlet(JcrNodeResource,
type=david, superType=null, path=/content/david/_your_title_)} Using
servlet org.apache.sling.servlets.get.DefaultGetServlet
0 (2010-06-22 16:57:55) TIMER_END{0,ServletResolution}
URI=/content/david/_your_title_.pdf handled by
Servlet=org.apache.sling.servlets.get.DefaultGetServlet
0 (2010-06-22 16:57:55) LOG Applying request filters
0 (2010-06-22 16:57:55) LOG Calling filter:
org.apache.sling.engine.impl.debug.RequestProgressTrackerLogFilter
0 (2010-06-22 16:57:55)
TIMER_START{org.apache.sling.servlets.get.DefaultGetServlet#0}
0 (2010-06-22 16:57:55) LOG No renderer for extension pdf
0 (2010-06-22 16:57:55) TIMER_START{handleError:status=404}

Am I missing something to correctly handle the request?


-- 
Federico

Re: JAR dependency for a bundle

Posted by Justin Edelson <ju...@gmail.com>.
On 6/22/10 10:06 AM, Bertrand Delacretaz wrote:
> Hi Federico,
> 
> On Tue, Jun 22, 2010 at 3:33 PM, Federico Paparoni
> <fe...@gmail.com> wrote:
>> I'm creating a new bundle to test a servlet that manage a new extension.
>> I have dependency with iText and, obviously, when I try to deploy the bundle
>> I receive this error in log
>>
>> ...(org.osgi.framework.BundleException: Unresolved constraint in bun
>> dle david [64]: package; (package=com.itextpdf.text.pdf))
> 
>> ... What are the best practises in that case? Where I have to put the dependency
>> JAR?...
> 
> Best is to find an OSGi bundle that exports the required iText
> classes. Many Apache projects (like commons.a.o) now include the OSGi
> metadata in their standard jars, so you can just load them as bundles.
> 
> I don't know if that's the case for iText, searching "itext osgi
> bundle" on google should help find out if such bundles are available.
> Install the bundle (using OSGi console is the easiest for a quick
> test) , and check the OSGi console to see if it exports the packages
> that you need.
FWIW, there is bundle for iText in the SpringSource bundle repository:
http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.lowagie.text&version=2.0.8

Justin

> 
> If you cannot find an iText bundle, you could "OSGify" an existing
> iText jar using the bnd tool or the maven-bundle-plugin to add the
> required MANIFEST.MF information to it.
> 
> Last (and least optimal) solution is to embed the iText classes in
> your bundle using the Embed-Dependency option of the
> maven-bundle-plugin, see
> http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
> 
> That last option might be the easiest for a quick test, the problem is
> that it adds bloat to your bundle and if another bundle needs those
> classes that would lead to duplication.
> 
> Hope this helps,
> -Bertrand


Re: JAR dependency for a bundle

Posted by Jos Snellings <Jo...@pandora.be>.
Just add:
|<dependency> <groupId>com.lowagie.text</groupId> 
<artifactId>com.springsource.com.lowagie.text</artifactId> 
<version>2.0.8</version> </dependency>
|to the dependencies in your pom.xml

Upon packaging, maven would add the iText bundle to your maven 
repository, make sure the classes that use iText get
"wired" to the right ones.
It is good to explicitly state the dependency in the import statements 
of your bundle, felix maven plugin-wise that is:
<Import-Package>|com.springsource.com.lowagie.text;version="2.0.8"|</Import-Package>

Now, I do not know if this is the very latest version.

Cheers,
Jos




On 06/24/2010 02:40 PM, Federico Paparoni wrote:
> 2010/6/24 Jos Snellings<Jo...@pandora.be>
>
>    
>> Hi Federico!
>>
>> There actually is a bundle for iText:
>>
>> http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.lowagie.text&version=2.0.8&searchType=bundlesByName&searchQuery=iText
>>
>> I did not try it out myself.
>> Check out if you can use that one.
>>
>> Cheers,
>> Jos
>>
>>
>>
>>      
> Hi Jos,
>
> to use it I have only to import in my project pom and then the bundle can be
> installed?
>
>    


Re: JAR dependency for a bundle

Posted by Federico Paparoni <fe...@gmail.com>.
2010/6/24 Jos Snellings <Jo...@pandora.be>

> Hi Federico!
>
> There actually is a bundle for iText:
>
> http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.lowagie.text&version=2.0.8&searchType=bundlesByName&searchQuery=iText
>
> I did not try it out myself.
> Check out if you can use that one.
>
> Cheers,
> Jos
>
>
>

Hi Jos,

to use it I have only to import in my project pom and then the bundle can be
installed?

-- 
Federico

Re: JAR dependency for a bundle

Posted by Jos Snellings <Jo...@pandora.be>.
Hi Federico!

There actually is a bundle for iText:
http://www.springsource.com/repository/app/bundle/version/detail?name=com.springsource.com.lowagie.text&version=2.0.8&searchType=bundlesByName&searchQuery=iText

I did not try it out myself.
Check out if you can use that one.

Cheers,
Jos




On 06/24/2010 02:20 PM, Federico Paparoni wrote:
> Hi
>
> 2010/6/22 Bertrand Delacretaz<bd...@apache.org>
>    
>>
>> If you cannot find an iText bundle, you could "OSGify" an existing
>> iText jar using the bnd tool or the maven-bundle-plugin to add the
>> required MANIFEST.MF information to it.
>>
>>
>>      
> I'm creating a bundle for iText using this guide (
> http://felix.apache.org/site/creating-bundles-using-bnd.html).
> But I have some questions related. What I have to put in the Export-Package,
> Private-Package tag of this bundle?
> iText uses class from rt.jar and if I put it as system dependency I create a
> jar of 22MB!
> I think there is something about "bundling" that I didn't understand.
> And when I finally create this bundle using maven, how can I declare it in
> my pom project to be included in Sling?
> Can anyone help me?
>
>    


Re: JAR dependency for a bundle

Posted by Federico Paparoni <fe...@gmail.com>.
Hi

2010/6/22 Bertrand Delacretaz <bd...@apache.org>
>
>
> If you cannot find an iText bundle, you could "OSGify" an existing
> iText jar using the bnd tool or the maven-bundle-plugin to add the
> required MANIFEST.MF information to it.
>
>
I'm creating a bundle for iText using this guide (
http://felix.apache.org/site/creating-bundles-using-bnd.html).
But I have some questions related. What I have to put in the Export-Package,
Private-Package tag of this bundle?
iText uses class from rt.jar and if I put it as system dependency I create a
jar of 22MB!
I think there is something about "bundling" that I didn't understand.
And when I finally create this bundle using maven, how can I declare it in
my pom project to be included in Sling?
Can anyone help me?

-- 
Federico

Re: JAR dependency for a bundle

Posted by Bertrand Delacretaz <bd...@apache.org>.
Hi Federico,

On Tue, Jun 22, 2010 at 3:33 PM, Federico Paparoni
<fe...@gmail.com> wrote:
> I'm creating a new bundle to test a servlet that manage a new extension.
> I have dependency with iText and, obviously, when I try to deploy the bundle
> I receive this error in log
>
> ...(org.osgi.framework.BundleException: Unresolved constraint in bun
> dle david [64]: package; (package=com.itextpdf.text.pdf))

>... What are the best practises in that case? Where I have to put the dependency
> JAR?...

Best is to find an OSGi bundle that exports the required iText
classes. Many Apache projects (like commons.a.o) now include the OSGi
metadata in their standard jars, so you can just load them as bundles.

I don't know if that's the case for iText, searching "itext osgi
bundle" on google should help find out if such bundles are available.
Install the bundle (using OSGi console is the easiest for a quick
test) , and check the OSGi console to see if it exports the packages
that you need.

If you cannot find an iText bundle, you could "OSGify" an existing
iText jar using the bnd tool or the maven-bundle-plugin to add the
required MANIFEST.MF information to it.

Last (and least optimal) solution is to embed the iText classes in
your bundle using the Embed-Dependency option of the
maven-bundle-plugin, see
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html

That last option might be the easiest for a quick test, the problem is
that it adds bloat to your bundle and if another bundle needs those
classes that would lead to duplication.

Hope this helps,
-Bertrand