简体   繁体   English

OSGI传递依赖项级别

[英]OSGI transitive dependencies level

I am currently trying to bundle a nonOSGI maven project. 我目前正在尝试捆绑nonOSGI Maven项目。 Right now, I have something like, 现在,我有这样的事情,

 <?xml version="1.0" encoding="UTF-8"?>
 <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>

<!-- The Basics -->
<artifactId>Project1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
    <dependency>
        <groupId>internal.commons</groupId>
        <artifactId>internalcommons</artifactId>
        <version>1.5</version>
    </dependency>
    <dependency>
        <groupId>jdom</groupId>
        <artifactId>jdom</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies> 
<parent>
    <groupId>internal</groupId>
    <artifactId>jar-project</artifactId>
    <version>1.0</version>
</parent>
<name>Project 1</name>

<build> 
    <directory>${basedir}/bundles</directory>
    <plugins>
        <plugin>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Name>${project.name}</Bundle-Name>
                    <Bundle-Version>1.0</Bundle-Version>
                    <Import-Package>*;resolution:=optional</Import-Package>
                    <Embed-Dependency>*</Embed-Dependency>
                    <Embed-Transitive>true</Embed-Transitive>
                </instructions>
            </configuration>
        </plugin>       
    </plugins>  
</build>

My nonOSGI bundle however depends on various different jars, some of these jars have dependencies too. 但是,我的nonOSGI捆绑包依赖于各种不同的jar,其中一些jar也具有依赖性。 When I bundle the nonOSGI maven project, I can only get the immediate dependencies of this bundle, when I use bundleall, I get an error relating to xml-apis:xml-apis:jar:2.6.2. 当我捆绑nonOSGI maven项目时,我只能得到该捆绑包的直接依赖关系,当我使用bundleall时,会出现与xml-apis:xml-apis:jar:2.6.2有关的错误。 I COULD create a bundles of all the dependencies if there is no other option but there are just too many dependencies. 如果没有其他选择,但存在太多依赖关系,我可以创建所有依赖关系的捆绑包。

Any help would be appreciated! 任何帮助,将不胜感激!

Well, 好,

According to the posted stacktrace there is no xml-apis:xml-apis:2.6.2 artifact in the central repo . 根据发布的stacktrace, 中央仓库中没有xml-apis:xml-apis:2.6.2工件。 I suppose it should be xerces:xmlParserAPIs:2.6.2 . 我想应该是xerces:xmlParserAPIs:2.6.2 Here is updated pom that does not have problems with embedding deps: 这是更新的pom,它没有嵌入dep的问题:

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <!-- The Basics -->
    <groupId>internal</groupId>
    <artifactId>Project1</artifactId>
    <version>1.0</version>
    <packaging>bundle</packaging>

    <name>Project 1</name>

    <dependencies>
        <dependency>
            <groupId>jdom</groupId>
            <artifactId>jdom</artifactId>
            <version>1.0</version>
        </dependency>
        <dependency>
            <groupId>xerces</groupId>
            <artifactId>xmlParserAPIs</artifactId>
            <version>2.6.2</version>
        </dependency>
    </dependencies> 

    <build> 
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Name>${project.name}</Bundle-Name>
                        <Bundle-Version>1.0</Bundle-Version>
                        <Import-Package>*;resolution:=optional</Import-Package>
                        <Embed-Dependency>*</Embed-Dependency>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>       
        </plugins>  
    </build>

</project>

Notice using packaging=bundle . 请注意使用packaging=bundle To build just execute mvn package . 要构建,只需执行mvn package

Although maven-bundle-plugin helps with embedding dependencies I highly recommend you not to do it if it's possible to achieve higher modularity of your project. 尽管maven-bundle-plugin有助于嵌入依赖项,但我强烈建议您不要这样做,如果有可能实现更高的项目模块化。 There are repos with prebuilt osgi bundles, for example: apache servicemix bundles , spring enterprise bundle repository , etc. 有带有预建osgi捆绑软件的存储库 ,例如: apache servicemix捆绑软件spring企业捆绑软件存储库等。

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

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