简体   繁体   中英

Error deploying third party jar files in karaf

I am trying to deploy a bundle in apache-karaf 3.0.3 which contains certain number of third party jar files which i am embedding inside, since the third party jar files are non OSGi bundles. Out of which one jar file contains an import statement in a java file which doesn't exist anymore in the latest version of jar file.(I didn't have the olderversion of jar file).

eg: jar file 1 - Class1 - import com.java.test.io

While deploying my application bundle with the jar files i am facing an error.

Error executing command: Error executing command on bundles: Unable to execute command on bundle 391: The bundle "com.test.example.bundle_0.1.0.SNAPSHOT [391]" could not be resolved. Reason: Missing Constraint: Import-Package: com.java.test.io; version="0.0.0"

I am trying to replicate the scenario with simple java application, it works as expected. My assumption is that karaf will scan all the import statements and check whether there is a proper export package(package level permission) exists for the appropriate import statment. Can anybody explain why java application runs and in karaf it fails?

pom.xml

<plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>mybundlename</Bundle-SymbolicName>
                        <Embed-Dependency>jar1,jar2,jar3,jar4</Embed-Dependency>

                    </instructions>
                </configuration>
            </plugin>
        </plugins>

What matters is not the package import in your class but the package import in your bundle's MANIFEST.

If your code works outside of an OSGi container, then it means that the imported package is not required at runtime in your particular usage scenario. Or it is not required at all and should be cleaned up.

You either have to deploy a bundle to satisfy the import or you have to suppress the addition of the import of com.java.test.io when building your bundle. With the maven-bundle-plugin you can achieve this like so:

<instructions>
    <Embed-Dependency>...</Embed-Dependency>
    <Import-Package>
        !com.java.test.io.*,
        *
    </Import-Package>
</instructions>

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