简体   繁体   English

使用 maven 中的内联 jar 文件构建 osgi 包

[英]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.我在将 maven jar 文件添加到 osgi 包时遇到了多个问题,但让我们从最重要的开始:我想在 osgi 包中包含所有相关的 jar 文件。

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.所以我的 pom.xml 列出了所有的依赖,都可以在 Eclipse 中编译。 When I run maven with the goal bundle:manifest a manifest file gets created listing the import packages correctly.当我使用目标 bundle:manifest 运行 maven 时,会创建一个清单文件,正确列出导入包。 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'许多行之一的确切错误消息是: 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.但它应该使用来自 maven 的 jar 文件。 And copy the jar file into the ${project.home}/target directory.并将 jar 文件复制到 ${project.home}/target 目录中。 But a mvn install does not add anything into the target/dependency directory.但是 mvn install 不会在目标/依赖目录中添加任何内容。 Still empty.还是空的。

I have tried multiple things for 5 hours now but can't get it to work.我现在已经尝试了 5 个小时的多种方法,但无法使其正常工作。

Any hints anybody?任何提示任何人?

pom.xml snippet pom.xml 片段

<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.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:完整的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.首先确定哪些传递依赖是 OSGi 包。 Add them as explicit dependencies with scope runtime, but exlude them in the Embed-Dependency instruction.将它们添加为作用域运行时的显式依赖项,但将它们排除在 Embed-Dependency 指令中。

The 3 non-OSGi dependency should have the scope "provided" so they are only considered during the build. 3 非 OSGi 依赖项应具有“提供”的范围,因此仅在构建期间考虑它们。 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).确保使用 Embed-Dependency 和 Embed-Transitive 指令将它们及其所有非 OSGi 依赖项添加到包中(检查生成的包 JAR 文件)。

You probably don't need to copy them with dependency:copy-dependencies as they will be available via this bundle.您可能不需要使用 dependency:copy-dependencies 复制它们,因为它们可以通过这个包获得。

Only this bundle and its OSGi runtime dependencies will have to be copied.只需复制此包及其 OSGi 运行时依赖项。

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).确保应用程序中任何其他包所需的嵌入式 JAR 的每个包都被导出(目前,Export-Package 指令是空的,我不清楚哪个包正在寻找“org.apache.commons.pool”。 impl”包)。

Make sure every package of the OSGi runtime dependencies, which are required by the embedded JARs, are imported using the Import-Package instruction.确保使用 Import-Package 指令导入嵌入式 JAR 所需的 OSGi 运行时依赖项的每个包。 Exclude the packages you don't require.排除不需要的包。

Okay, one part I found out.好的,我发现了一部分。 The maven goal is dependency:copy-dependencies to copy the dependencies. maven 的目标是 dependency:copy-dependencies 来复制依赖。 :sight: Now the folder contains the jar files.... :sight: 现在该文件夹包含 jar 文件....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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