Custom taglib not loaded with Liferay7

OK, I managed to figure this out by myself.

The directory layout needs to be like this:

+---java
|   \---com
|       \---mypackage
|           |   
|           +---portlet
|           |       MyPortlet.java
|           |       
|           \---tags
|                   LabelTag.java
|                   
\---resources
    +---content
    |       Language.properties
    |       
    +---META-INF
    |   |   my_tags.tld
    |   |   
    |   \---resources
    |       |   view.jsp
    |               
    \---WEB-INF

In contrast to some hints on the internet, the file taglib-mappings.properties is not needed. If it is present, Liferay throws a gazillion of exceptions because the Freemarker engine tries to access the taglibs that are referenced in taglib-mappings.properties.

And my_tags.tld contains the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>
  <tlib-version>1.0</tlib-version>
  <jsp-version>1.1</jsp-version>
  <short-name>ka</short-name>
  <uri>http://example.com/tld/my_tags</uri>

  <tag>
    <name>label</name>
    <tag-class>com.mypackage.tags.LabelTag</tag-class>
    <body-content>scriptless</body-content>
    <attribute>
      <name>labelText</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
      <type>java.lang.String</type>
    </attribute>
  </tag>
</taglib>

The in the JSP page, the tag is defined as:

<%@ taglib uri="http://example.com/tld/my_tags" prefix="my" %>

I do not include a Require-Capability: for my own tags in the OSGI MANIFEST.MF file.

I only include that for the standard JSTL and Liferay tags:

Require-Capability: osgi.extender;filter:="(&(osgi.extender=jsp.taglib)(
 uri=http://java.sun.com/portlet_2_0))",osgi.extender;filter:="(&(osgi.e
 xtender=jsp.taglib)(uri=http://liferay.com/tld/aui))",osgi.extender;fil
 ter:="(&(osgi.extender=jsp.taglib)(uri=http://liferay.com/tld/portlet))
 ",osgi.extender;filter:="(&(osgi.extender=jsp.taglib)(uri=http://lifera
 y.com/tld/theme))",osgi.extender;filter:="(&(osgi.extender=jsp.taglib)(
 uri=http://liferay.com/tld/ui))",osgi.ee;filter:="(&(osgi.ee=JavaSE)(ve
 rsion=1.8))"

However, I did need to exclude some packages in the OSGI bnd.bnd file that were included due to the dependency on javax.servlet.jsp and jstl

Import-Package: \
    .....
    !com.ibm.*,\
    !com.sun.*,\
    !javax.jmdns.*,\
    *