On Sunday, March 29, 2020 5:14:48 PM CEST JCR wrote: > > Am Sa., 28. März 2020 um 20:55 Uhr schrieb JCR <j...@proxymit.net>: > >> Hello
Hi Juerg, > >> I wrote a very simple POJO, built it as OSGi bundle and deployed it to > >> Sling11. Here's the source: > >> > >> package rome.testly.testly1; > >> import org.osgi.service.component.annotations.Component; > >> > >> @Component(service=SlingFutil.class ) > >> public class SlingFutil { > >> > >> public String nonsense() { > >> > >> return "This is nonsense"; > >> > >> } > >> > >> } > >> > >> The component/service appears on the Felix console: > >> > >> symbolic Name testly1 > >> Version 0.0.1.202003271754 > >> Bundle Location > >> > >> /home/juerg/eclipse-workspace/testly1/target/classes > >> > >> Last Modification Fri Mar 27 18:54:01 CET 2020 > >> Start Level 20 > >> Exported Packages --- > >> Imported Packages org.osgi.framework,version=1.9.0 from > >> org.apache.felix.framework (0) > >> <http://localhost:8080/system/console/bundles/0> > >> org.osgi.service.component,version=1.4.0 from org.apache.felix.scr (50) > >> <http://localhost:8080/system/console/bundles/50> > >> org.slf4j,version=1.7.25 from slf4j.api (20) > >> <http://localhost:8080/system/console/bundles/20> > >> Service ID 477 <http://localhost:8080/system/console/services/477> > >> Types: java.lang.Runnable > >> Component Name: rome.testly.testly1.SimpleDSComponent > >> Component ID: 323 > >> Service ID 478 <http://localhost:8080/system/console/services/478> > >> Types: rome.testly.testly1.SlingFutil > >> Component Name: rome.testly.testly1.SlingFutil > >> Component ID: 324 > >> > >> > >> > >> Now I try to call SlingFutil.nonsense() from a JSP: > >> > >> ... > >> <%@ page import="javax.jcr.*, > >> > >> org.apache.sling.api.resource.Resource, > >> rome.testly.testly1.*" > >> > >> %> > >> ... > >> <% > >> SlingFutil some = new SlingFutil(); > >> %> > >> ... > >> > >> At this point, the JSP compiler complains that the type (SlingFutil) is > >> unknown. > >> I also tried > >> > >> sling.getService(rome.testly.testly1.SlingFutil.class); > >> > >> instead, but the result is the same. > >> > >> This used to work well at BND times of Sling, so I don't know what's > >> wrong with this R7 code. > >> > >> Thanks, > >> Juerg > > > > On 28.03.20 21:15, Jörg Hoh wrote: > >> Hi Juerg, > >> > >> Looks like your bundle does not export that class, so it's not available > >> outside of that bundle. > >> > >> Jörg > > Hi Jörg > > The class is declared as @Component (see above). Do I need any other > declaration to make the export happen? It depends on the plugin (and version) you use. See the configuration in Sling Parent for bnd Maven Plugin: -exportcontents: ${removeall;${packages;VERSIONED};${packages;CONDITIONAL}} https://github.com/apache/sling-parent/blob/master/sling-bundle-parent/ pom.xml#L71 And here is an example for a versioned (and therefore exported) package: @Version("2.3.4") package org.apache.sling.api; https://github.com/apache/sling-org-apache-sling-api/blob/master/src/main/ java/org/apache/sling/api/package-info.java Regards, O. > Thanks, > Juerg