Skip to content

Commit

Permalink
Add loading declared native libs from OSGi bundles (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibauersachs authored Feb 18, 2023
1 parent c37a6c7 commit d59644a
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 5 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ be manually listed and the "framework" must be told to start them.
var activators = List.of(MyBundle.class);

// then prepare the "framework"
var options = new HashMap<String, String>();
options.put(Constants.FRAMEWORK_BEGINNING_STARTLEVEL, "2");
var options = Map.ofConstants.FRAMEWORK_BEGINNING_STARTLEVEL, "2");
Framework fw = new FrameworkImpl(options, Main.class.getClassLoader());
fw.init();
var bundleContext = fw.getBundleContext();
Expand All @@ -33,3 +32,9 @@ for (Class<? extends BundleActivator> activator : activators) {
fw.start();
fw.waitForStop(0);
```

## Native Libraries from Bundles

To use bundles that declare native libraries in their manifest and are loading
them via `System.loadLibrary(String)`, use the `BundleClassLoader` to run the
framework init code. They should then work like in a full OSGi implementation.
30 changes: 28 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version>
<lombok.version>1.18.26</lombok.version>
</properties>

<dependencies>
Expand All @@ -59,6 +60,25 @@
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>

<!-- test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -81,11 +101,17 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>11</source>
<target>11</target>
<release>11</release>
<compilerArgs>
<arg>-Xlint:all,-serial</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>

Expand Down
Loading

0 comments on commit d59644a

Please sign in to comment.