简体   繁体   中英

Build an osgi bundle with inline jar files from maven

I have multiple issues with adding maven jar files to the osgi bundle, but let's start with the most important: I'd like to include all dependent jar files in the osgi bundle.

I know that is not ideal and all but bear with me.

So my pom.xml lists all dependencies, all can be compiled in Eclipse. When I run maven with the goal bundle:manifest a manifest file gets created listing the import packages correctly. But most packages are error'ed out with the message "no available bundle exports".

Exact error message for one of the many lines is: No available bundle exports package 'org.apache.commons.pool.impl'

Understood, there is no dependent bundle for it. Of course. But it should use the jar file from maven. And copy the jar file into the ${project.home}/target directory. But a mvn install does not add anything into the target/dependency directory. Still empty.

I have tried multiple things for 5 hours now but can't get it to work.

Any hints anybody?

pom.xml snippet

<plugin>
        <groupId>org.apache.felix</groupId>
        <artifactId>maven-bundle-plugin</artifactId>
        <version>4.2.0</version>
        <extensions>true</extensions>
        <configuration>
                <instructions>
                        <Import-Package>
                                *
                        </Import-Package>
                        <Export-Package>
                        </Export-Package>
                        <Bundle-Activator>
                                io.rtdi.sdiadapter.parquetadapter.Activator
                        </Bundle-Activator>
                        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                        <Embed-Directory>target/dependency</Embed-Directory>
                </instructions>
                <manifestLocation>${project.basedir}/META-INF</manifestLocation>
        </configuration>
</plugin>

Generated manifest.mf

Manifest-Version: 1.0
Bnd-LastModified: 1562870469538
Build-Jdk: 1.8.0_212
Built-By: wdaehn
Bundle-Activator: io.rtdi.sdiadapter.parquetadapter.Activator
Bundle-ClassPath: .,target/dependency/parquet-column-1.10.0.jar,target/d
 ependency/hadoop-client-3.2.0.jar,target/dependency/parquet-hadoop-1.10
 .0.jar
Bundle-ManifestVersion: 2
Bundle-Name: ParquetAdapter
Bundle-SymbolicName: ParquetAdapter
Bundle-Version: 0.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Embed-Dependency: *;scope=compile|runtime
Embed-Directory: target/dependency
Embedded-Artifacts: target/dependency/parquet-column-1.10.0.jar;g="org.a
 pache.parquet";a="parquet-column";v="1.10.0",target/dependency/hadoop-c
 lient-3.2.0.jar;g="org.apache.hadoop";a="hadoop-client";v="3.2.0",targe
 t/dependency/parquet-hadoop-1.10.0.jar;g="org.apache.parquet";a="parque
 t-hadoop";v="1.10.0"
Import-Package: com.sap.hana.dp.adapter.sdk,com.sap.hana.dp.adapter.sdk.
 parser,org.apache.commons.codec.binary;version="[1.10,2)",org.apache.co
 mmons.pool;version="[1.6,2)",org.apache.commons.pool.impl;version="[1.6
 ,2)",org.apache.hadoop.classification,org.apache.hadoop.conf,org.apache
 .hadoop.fs,org.apache.hadoop.io,org.apache.hadoop.io.compress,org.apach
 e.hadoop.mapred,org.apache.hadoop.mapreduce,org.apache.hadoop.mapreduce
 .counters,org.apache.hadoop.mapreduce.lib.input,org.apache.hadoop.mapre
 duce.lib.map,org.apache.hadoop.mapreduce.lib.output,org.apache.hadoop.m
 apreduce.task,org.apache.hadoop.util,org.apache.log4j;version="[1.2,2)"
 ,org.apache.parquet.bytes,org.apache.parquet.compression,org.apache.par
 quet.format,org.codehaus.jackson;version="[1.9,2)",org.codehaus.jackson
 .map;version="[1.9,2)",org.osgi.framework,org.slf4j;version="[1.7,2)",o
 rg.xerial.snappy;version="[1.1,2)"
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Tool: Bnd-4.2.0.201903051501

complete pom:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ParquetAdapter</groupId>
    <artifactId>ParquetAdapter</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>bundle</packaging>
    <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>4.2.0</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Import-Package>
                            *
                        </Import-Package>
                        <Export-Package>
                        </Export-Package>
                        <Bundle-Activator>
                            io.rtdi.sdiadapter.parquetadapter.Activator
                        </Bundle-Activator>
                        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
                        <Embed-Directory>target/dependency</Embed-Directory>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                    <manifestLocation>${project.basedir}/META-INF</manifestLocation>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.apache.parquet</groupId>
            <artifactId>parquet-column</artifactId>
            <version>1.10.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>3.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.parquet</groupId>
            <artifactId>parquet-hadoop</artifactId>
            <version>1.10.0</version>
        </dependency>
    </dependencies>
</project>

First make sure which of the transitive dependencies are OSGi bundles. Add them as explicit dependencies with scope runtime, but exlude them in the Embed-Dependency instruction.

The 3 non-OSGi dependency should have the scope "provided" so they are only considered during the build. Make sure with the Embed-Dependency and the Embed-Transitive instruction that they and all their non-OSGi dependencies are added to the bundle (check the generated bundle JAR file).

You probably don't need to copy them with dependency:copy-dependencies as they will be available via this bundle.

Only this bundle and its OSGi runtime dependencies will have to be copied.

Make sure every package of the embedded JARs which are required by any other bundle in your application gets exported (currently the Export-Package instruction is empty and it's not clear to me which bundle is looking for the "org.apache.commons.pool.impl" package).

Make sure every package of the OSGi runtime dependencies, which are required by the embedded JARs, are imported using the Import-Package instruction. Exclude the packages you don't require.

Okay, one part I found out. The maven goal is dependency:copy-dependencies to copy the dependencies. :sight: Now the folder contains the jar files....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM