简体   繁体   中英

OSGI transitive dependencies level

I am currently trying to bundle a nonOSGI maven project. 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. 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. 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 . I suppose it should be xerces:xmlParserAPIs:2.6.2 . Here is updated pom that does not have problems with embedding deps:

<?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 . To build just execute 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. There are repos with prebuilt osgi bundles, for example: apache servicemix bundles , spring enterprise bundle repository , etc.

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