Issue with creating custom tag library using OSGI bundle | Community
Skip to main content
October 16, 2015
Solved

Issue with creating custom tag library using OSGI bundle

  • October 16, 2015
  • 19 replies
  • 8152 views

I am trying to create custom tag libs by using OSGI bundles in cq. Actually i created all the necessary files but i could not place my mytags.tld file under META-INF folder in build time. For that i used "maven-bundle-plugin" plugin. Here is my code to include the resource in META-INF folder

    <plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
        <instructions>
        <Include-Resource>META-INF/myTags-${project.version}.tld=target/classes/META-INF/myTags-${project.version}.tld</Include-Resource>
        </instructions>
        <Export-Package>com.mine.*</Export-Package>
        <Import-Package>*;resolution:=optional</Import-Package>                    
        </configuration>
    </plugin>

Note: i have placed my tag file under "src\main\resources\META-INF\myTags"
I have used "<Include-Resource>" to include my tld file. But i could see my tld file under META-INF folder after jar file is created.

Could you anyone tell what could be the problem?

 

Thanks

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Ojjis

Do you get any other errors?
This is an example how  you can set it up (note that this is just a simple test for a function but works the same way for tags):

1) In the tld file:

<?xml version="1.0" encoding="ISO-8859-1" ?> <taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" version="2.0"> <description>My tag library</description> <tlib-version>1.0</tlib-version> <short-name>mytags</short-name> <uri>http://my.company.com/taglibs/mytags/1.0</uri> <function> <name>getSomeText</name> <function-class>com.mycompany.common.MyTest</function-class> <function-signature>String getSomeText(java.lang.String)</function-signature> </function> </taglib>

2. In the java file for the tag (called MyTest.java in the package com.mycompany.common):

public class MyTest { public static String getSomeText(String name) { return "Hi " + name + ", here is some text for you"; } }

3. Then exported the classes (in the pom) as you did with:
 

//... <Export-Package>com.mycompany.common.*</Export-Package> //..

4. Then in the .JSP file

//.. code <%@taglib prefix="mycompany" uri="http://my.company.com/taglibs/mytags/1.0" %> <div class="test-div"> ${mycompany:getSomeText("Johan")} </div> //... more code


Hope you get the idea.
/Johan

19 replies

Ojjis
Level 7
October 16, 2015

I've got the same setup as you have written and put the file in the same location,
but I have the following line just underneat <import-package></import-package>:

<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
 

Maybe you could try and see if that solves your problem ?
Do you get any build messages/errors ?

/Johan

October 16, 2015

Am i using <Include-Resource> tag correctly? do i need to declare anywhere in my pom.xml in order to use Include-Resource tag?

I am sure there is a way to achieve it. Could you please suggest is there any other way to achieve this one?

Can you please share your <Include-Resource> tag alone if possible ? so that i can incorporate it.

Thanks

Ojjis
Level 7
October 16, 2015

I've done just like you wrote above,  META-INF/mytld.tld=target/classes/META-INF/mytld.tld 
Could there be a problem with the copying of files (during the package phase) with the maven-resources-plugin  ?
 

October 16, 2015

Hi,

I have removed the version no and tried it like this

<Include-Resource>myTags.tld=target/classes/META-INF/myTags.tld</Include-Resource>

Bu ti am getting the error like "[ERROR] Bundle com.mine-bundle:bundle:1.0-SNAPSHOT : Input file does not exist: target/classes/META-INF/myTags.tld"

Here is my tld file

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<taglib xmlns="http://java.sun.com/xml/ns/javaee" version="2.1">
    <tlib-version>0.0.1</tlib-version>
    <short-name>POC</short-name>
    <uri>http://mine.com/bundles/cq/tags123</uri>
    <tag>
      <name>hello</name>
      <tagclass>com.mine.Hello</tagclass>
      <bodycontent>empty</bodycontent>
      <info>This is a simple hello tag</info>
    <attribute>
      <name>name</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
    </tag>
</taglib>


Does it related to tlib-version?

Can you please tell how did you solve this issue? Is it possible you to provide your "maven-bundle-plugin" plugin? So that i can incorporate it

Thanks

Ojjis
Level 7
October 16, 2015

Okey. Seems to be a problem with the version numbers there.
The extra -${project.version} is somehow not recognised. Can you first try to verify that it works without that like:
myTags.tld=target/classes/META-INF/myTags.tld

In your tld file. Have you set the right version number (the same) there aswell ? 

October 16, 2015

Yes, My tld name is myTags.tld which is located into src\main\resources\META-INF\myTags.tld.

I have tried it like this "<Include-Resource>META-INF/myTags.tld=target/classes/META-INF/myTags.tld</Include-Resource>"

Again i am getting the error like as below

[ERROR] Bundle com.mine-bundle:bundle:1.0-SNAPSHOT : Input file does not exist: target/classes/META-INF/myTags.tld

 

Thanks

Ojjis
Level 7
October 16, 2015

but your .tld file is not named myTags-1.0-SNAPSHOT.tld is it ?

Adobe Employee
October 16, 2015

You should remove all of that configuration from the bundle plugin. What you are describing is the default behavior and these configuration settings are only going to make your situation worse.

October 16, 2015

Hi Johan,

Thanks for your quick reply

I have included the above line in my pom.xml like

<plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <extensions>true</extensions>
        <configuration>
        <instructions>
        <Include-Resource>META-INF/myTags-${project.version}.tld=target/classes/META-INF/myTags-${project.version}.tld</Include-Resource>
        </instructions>
        <Export-Package>com.mine.*</Export-Package>
        <Import-Package>*;resolution:=optional</Import-Package>                    
        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
        </configuration>
    </plugin>

 

I am getting the same error as below

[ERROR] Bundle com.mine-bundle:bundle:1.0-SNAPSHOT : Input file does not exist: target/classes/META-INF/myTags-1.0-SNAPSHOT.tld

 

Thanks