On 30.03.20 16:18, JCR wrote:

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?

You need to have the package name appear in the "exported packages" section
of the bundle. The maven bundle plugin has some heuristics for reasonable
defaults.
Can you share your complete project code?

Jörg


On 29.03.20 21:08, Oliver Lietz wrote:

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

@Jörg: You can find the OSGi bundle code here: https://gitlab.com/yumeier/testly/-/tree/master/testly3             the calling JSP is here: https://gitlab.com/yumeier/testlyclient

@Oliver: -exportcontents: happy to check this, but gives me a hard time to find this line. Where (file) exactly would it be located?               I added the package⁻info.java (see also testly3 repo indicated above).

Due to some changes in the project structure (adding gitlab), the SlingFutil service does not appear anymore in the Felix console, while the generated class SimpleDSComponent appears seemingly without a problem. I still assume that I don't need to add the lifecycle methods in the/(each) POJO, right?

Thanks, Juerg


Not progressing. Package rome.testx.testaa with all its classes should be exported so it is usable by JSPs under jcr_root/apps (I am told).

I'm using version 1.2.2 of org.apache.sling.ide.m2e-feature.feature.group, hence the latest stable one.

I added this package-info.java:

@Version("1.0.0")
package rome.testx.testaa;

import org.osgi.annotation.versioning.Version;

According to this thread, this should export the package. But what I observe is, that MANIFEST.MF gets overriden on every change and even package-info is present, the package in there gets set back to to private:

Manifest-Version: 1.0
Bnd-LastModified: 1586195731720
Bundle-ManifestVersion: 2
Bundle-Name: testaa
Bundle-SymbolicName: testaa
Bundle-Version: 0.0.2.202004061755
Created-By: 11.0.6 (Ubuntu)
Import-Package: org.osgi.framework;version="[1.5,2)",org.osgi.service.
 component;version="[1.1,2)",org.slf4j;version="[1.7,2)"
Private-Package: rome.testx.testaa;version="1.0.0"
Provide-Capability: osgi.service;objectClass:List<String>="java.lang.R
 unnable"
Require-Capability: osgi.extender;filter:="(&(osgi.extender=osgi.compo
 nent)(version>=1.3.0)(!(version>=2.0.0)))",osgi.ee;filter:="(&(osgi.e
 e=JavaSE)(version=1.8))"
Service-Component: OSGI-INF/rome.testx.testaa.Radio.xml,OSGI-INF/rome.
 testx.testaa.SimpleDSComponent.xml
Tool: Bnd-3.5.0.201709291849

Consequently, the package remains unavailable to JSPs, the package is not visible to them and much less Radio.class.

There must be some hidden tweak. Thanks for any hint.
-Juerg


Reply via email to