commit | 73f49b6603f74686407237b88d25cce8982c9a76 | [log] [tgz] |
---|---|---|
author | Thomas Watson <tjwatson@us.ibm.com> | Wed Jan 29 08:26:04 2020 -0600 |
committer | GitHub <noreply@github.com> | Wed Jan 29 08:26:04 2020 -0600 |
tree | ed8e44ffd4b5881212bf58eef333a81d4350931b | |
parent | afd8f6741e89d389e302958779f6c3d8738da309 [diff] | |
parent | ad55699fbcd689a5cd2d9e0561ae5dd4277fb251 [diff] |
Merge pull request #26 from stbischof/p_structure [tests] restructure projects,names,packages,modules
Atomos - A Java Module Framework using OSGi Connect
Atomos requires an Equinox OSGi Framework implementation which supports OSGi Connect initially described in this OSGi blog post. The OSGi Connect specification is currently being developed as an RFC with the OSGi Alliance and the current version of the RFC can be found here. Currently a snapshot of the Equinox OSGi Framework is being used that implements the proposed OSGi Connect specification for an upcoming OSGi R8 Core specification. Source for the snapshot is found in https://git.eclipse.org/c/equinox/rt.equinox.framework.git in the osgiR8
branch and tempary binaries are pushed to https://github.com/tjwatson/atomos-temp-m2repo for Atomos. Atomos is an implementation of an OSGi Connect factory that can be used to create an OSGi Framework instance. Framework instances created with Atomos add support to the OSGi Framework that enables bundles to be installed which are managed outside of the OSGi Framework module layer. Currently Atomos supports three different modes for loading bundles from outside the OSGi module layer:
Java 11 must be used to build Atomos. Atomos build uses the latest 1.0.0.Beta2 version of the moditect plugin (https://github.com/moditect/moditect.git).
This plugin provides some cool utilities for adding module-infos to existing dependency JARs and building jlink
images. You can build the Atomos with the following:
mvn clean install -Pjava8
This should create a jlink image under atomos/atomos.examples/atomos.examples.jlink/target/atomos
. Executing the following command against the jlink image should produce a gogo shell prompt:
./bin/atomos
You should see the following output:
Registered Echo service from activator. ____________________________ Welcome to Apache Felix Gogo g!
In order to successfully build a jlink image all bundles included in the image must contain a module-info.class
, they cannot be automatic modules. The atomos/atomos.examples/atomos.examples.jlink
example uses the latest 1.0.0.Beta2
version of the moditect-maven-plugin
to add module-info.class
as necessary to the bundles used in the image.
You can also load additional modules into atomos at:
atomos.modules
option when launching atomos
. For example:atomos/bin/atomos atomos.modules=/path/to/more/modules
atomos:install
For example:atomos:install MyLayerName OSGI /path/to/more/modules
When doing that the additional modules will be loaded into a child layer where the Atomos OSGi Framework will control the class loaders. This will produce a class loader per module bundle installed. This has advantages because it allows the module class loader for the bundle to implement the org.osgi.framework.BundleReference
interface.
There are two examples projects that build native images using Graal Substrate:
atomos/atomos.examples/atomos.examples.substrate.equinox
- Using Eclipse Equinox Frameworkatomos/atomos.examples/atomos.examples.substrate.felix
- Using Apache Felix FrameworkThese two example projects are not built as part of the main Atomos build because the require an installation of GraalVM CE 19.3.1 (Java 8 or Java 11 can be used) and the native-image tools for Substrate. The Java 11 version of Graal Substrate does not currently support full introspection at image runtime of the Java Platform Module System. Atomos Module support expects to have full introspection of the Java Platform Module System when running on Java versions greater than Java 8. Therefore the example will run in basic class path mode for both Java 8 and Java 11 when running with a native substrate image. To build the Substrate example the main Atomos build must first be built using the Java 8 profile:
mvn clean install -Pjava8
Note that install
target must be used so that Atomos is installed into your local m2 repository. This still requires Java 11 to be used to build but the result allows the atomos.framework
JAR to be used on Java 8.
To build the native image you must to install the native image support for Graal (see https://www.graalvm.org/docs/reference-manual/native-image/). You need to run the gu
command that comes with Graal VM:
gu install native-image
Next you must switch to a Java installation of Graal with the Substrate native-image tools installed and then change into one of the atomos.examples.substrate
projects and run mvn clean package
This will create a target/atomos
executable. If you launch atomos
it will give you a gogo g!
prompt to run gogo commands. Also included in this example is a version of the Felix web console. The web console can be access with http://localhost:8080/system/console/bundles and the id/password is admin/admin.
For the Felix example a directory target/substrate_lib/
is created. This contains all the original bundle JARs that got compiled into the native image atomos
. In order to launch the native atomos
you must be in the directory containing both atomos
and the substrate_lib/
folder. This is a simple way for Atomos to discover the available bundlesand load additional bundle entries at runtime.
For the Equinox example the directory target/substrate_lib/
is not used. Instead the bundle entry resources are placed in an atomos/
folder which is placed on the classpath during native image compilation. The resources from the atomos/
folder are then included in the native image. The atomos/
folder has a file bundles.index
that contains information for Atomos to discover the bundles and their entries that are included in the native image.
Hopefully substrate will add full introspection to the Java Platform Module System in the future which would allow Atomos to discover the modules within the image and load them as bundles. If a proper module reader could be obtained and contain the necessary resources from the original bundle JARs then it would eliminate the need for the substrate_lib/
or atomos/
resource folder.