Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module path is not working #51

Closed
fipro78 opened this issue May 5, 2022 · 10 comments
Closed

module path is not working #51

fipro78 opened this issue May 5, 2022 · 10 comments

Comments

@fipro78
Copy link
Contributor

fipro78 commented May 5, 2022

I am trying to setup a simple example to better understand how Atomos can be used. The example looks similar to the example showed in the README, it just uses the most current versions of Equinox/Felix and I of course had to build Atomos locally, which makes it a 1.0.1-SNAPSHOT. I created setups for Equinox and Felix as the underlying OSGi framework.

Using the classpath variant both examples work fine.
Using the module path variant none of the examples is working.

For Equinox (org.eclipse.osgi-3.17.200.jar) I get the following exception:

java.lang.ClassNotFoundException: sun.misc.Unsafe
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.internal.url.MultiplexingFactory.<clinit>(MultiplexingFactory.java:61)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.storage.FrameworkExtensionInstaller.findAddURLMethod(FrameworkExtensionInstaller.java:62)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.storage.FrameworkExtensionInstaller.<clinit>(FrameworkExtensionInstaller.java:55)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.storage.Storage.<init>(Storage.java:222)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.storage.Storage.createStorage(Storage.java:184)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:108)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.launch.Equinox.<init>(Equinox.java:53)
        at org.eclipse.osgi@3.17.200-SNAPSHOT/org.eclipse.osgi.launch.EquinoxFactory.newFramework(EquinoxFactory.java:35)
        at org.apache.felix.atomos@1.0.1-SNAPSHOT/org.apache.felix.atomos.impl.base.AtomosBase.newFramework(AtomosBase.java:442)
        at org.apache.felix.atomos@1.0.1-SNAPSHOT/org.apache.felix.atomos.Atomos.main(Atomos.java:236)

For Felix (org.apache.felix.framework-7.0.3.jar) the felix-cache is created, but then nothing happens. The application does actually not start.

I attach the two examples as archive that contain also the start calls in Windows batch files.

atomos_felix.zip
atomos_equinox.zip

@tjwatson
Copy link
Member

tjwatson commented May 5, 2022

What version of Java are you using?

@fipro78
Copy link
Contributor Author

fipro78 commented May 5, 2022

openjdk version "11.0.14.1" 2022-02-08
OpenJDK Runtime Environment Temurin-11.0.14.1+1 (build 11.0.14.1+1)
OpenJDK 64-Bit Server VM Temurin-11.0.14.1+1 (build 11.0.14.1+1, mixed mode)

@tjwatson
Copy link
Member

tjwatson commented May 5, 2022

The issue is that Java Module System will only pull in the modules on the module path that are required from the starting module (you specified -m org.apache.felix.atomos). That does not pull in all your "modules" from the plugins/folder.

To add all your modules you need to specify the java option --add-modules=ALL-MODULE-PATH which will force all of the modules on the module path to be included in a JPMS runtime resolution.

But when I do that I get this:

java --add-modules=ALL-MODULE-PATH -p plugins/ -m org.apache.felix.atomos
java.lang.module.FindException: Module org.osgi.service.cm not found, required by org.fipro.ds.command

Note that we are in the process of removing org.osgi.service.cm from the org.eclipse.osgi.services and having it instead require-reexport this org.osgi.service.cm bundle. That may help you in this case. But for now I would avoid trying to use org.eclipse.osgi.services in such scenarios and instead pull in the OSGi WG bundles that provide the APIs as much as possible for the module path scenarios.

@tjwatson
Copy link
Member

tjwatson commented May 5, 2022

The exception you see from equinox is just an annoying printStackTrace we have in Equinox when we cannot load the Unsafe class. But we should continue on and still initialize the framework just fine.

@fipro78
Copy link
Contributor Author

fipro78 commented May 5, 2022

Well OSGi and JPMS seems to be a bigger issue. :)
I tried to create the simple examples using Bndtools and already got quite a lot of problems in that area. Will create a ticket there to share my experiences. For example the require statements where necessary to get the modules compiled in Eclipse and resolved, at runtime it fails with the module path as even the Felix bundles to not provide module infos.

Anyhow, if I remove the module-info.class from the corresponding jars, it passes my former modules, but then fails with this:

Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules org.eclipse.osgi.services and org.apache.felix.scr export package org.osgi.service.component to module org.apache.felix.atomos

Probably similar to the issue you described above.

The Felix setup then works, despite the "modify" command. Probably I forgot to export the package that contains the service implementation. Which is also something I do not fully understand as an OSGi guy. ;)

ERROR : bundle org.fipro.modifier.inverter:1.0.0.202205041325 (51)[org.fipro.modifier.inverter.StringInverter(6)] : Error during instantiation of the implementation object
java.lang.IllegalAccessException: class org.apache.felix.scr.impl.inject.internal.ComponentConstructorImpl (in module org.apache.felix.scr) cannot access class org.fipro.modifier.inverter.StringInverter (in module org.fipro.modifier.inverter) because module org.fipro.modifier.inverter does not export org.fipro.modifier.inverter to module org.apache.felix.scr

At least I know understand the issue better. And I will then continue with the Graal/Substrate example.

Thanks a lot for the fast response!

@fipro78
Copy link
Contributor Author

fipro78 commented May 5, 2022

Oh, btw, maybe it would be good to add the hint about the modules to load to the README. Because I simply followed the instructions and started the example the same way as explained there. Could be lead also others to the same issue.

@tjwatson
Copy link
Member

tjwatson commented May 5, 2022

Oh, btw, maybe it would be good to add the hint about the modules to load to the README. Because I simply followed the instructions and started the example the same way as explained there. Could be lead also others to the same issue.

Good idea, I updated the README with some hint there.

@tjwatson
Copy link
Member

tjwatson commented May 5, 2022

@rotty3000 has been doing some work recently here. Maybe he has some examples to point you to?

@rotty3000
Copy link
Contributor

@fipro78 I pinged you on the OSGi slack if you want to chat about what bnd has been working on in this area. Feel free to reach out.

@fipro78
Copy link
Contributor Author

fipro78 commented May 6, 2022

With the recommended updates to starting the runtime and the removal of the module-info from my bundles, things are working as expected. As you already updated the README to add the information about adding the modules, this ticket can be closed.

@fipro78 fipro78 closed this as completed May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants