Travelling Salesman
Travelling Salesman

Reputation: 2281

Jar file trying to install a bundle saved on its classpath shows "Cannot Find The File Specified"

In my code, I am embedding Apache Felix, and install a bundle as the following:

Bundle AB= adereContext.installBundle("file:ADEREBundle_1.0.0.201402211848.jar");
AB.start();

The bundle "ADEREBundle_1.0.0.201402211848.jar" is saved on the project directory, and so I assume that this should work.

Now, when I run this code in a normal java application, it shows no error, and the bundle is successfully installed.

However, when I jar my whole project (including the code above), and try to use it in another java application, it shows:

org.osgi.framework.BundleException: Unable to cache bundle: file:ADEREBundle_1.0.0.201402211848.jar
    at org.apache.felix.framework.Felix.installBundle(Felix.java:2870)
    at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:165)
    at org.apache.felix.framework.BundleContextImpl.installBundle(BundleContextImpl.java:138)
    at aderetest.Main.main(Main.java:40)
Caused by: java.io.FileNotFoundException: ADEREBundle_1.0.0.201402211848.jar (The system cannot find the file specified)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:120)
    at java.io.FileInputStream.<init>(FileInputStream.java:79)
    at sun.net.www.protocol.file.FileURLConnection.connect(FileURLConnection.java:70)
    at sun.net.www.protocol.file.FileURLConnection.getInputStream(FileURLConnection.java:161)
    at org.apache.felix.framework.util.SecureAction.getURLConnectionInputStream(SecureAction.java:524)
    at org.apache.felix.framework.cache.JarRevision.initialize(JarRevision.java:165)
    at org.apache.felix.framework.cache.JarRevision.<init>(JarRevision.java:77)
    at org.apache.felix.framework.cache.BundleArchive.createRevisionFromLocation(BundleArchive.java:878)
    at org.apache.felix.framework.cache.BundleArchive.reviseInternal(BundleArchive.java:550)
    at org.apache.felix.framework.cache.BundleArchive.<init>(BundleArchive.java:153)
    at org.apache.felix.framework.cache.BundleCache.create(BundleCache.java:277)
    at org.apache.felix.framework.Felix.installBundle(Felix.java:2866)

What is so special about the case of jaring my project, and which made my bundle file not seen? The bundle is for sure on the root directory of the jar, and I can see it.

How can I solve my problem? Thanks.

Note: having the bundle outside my jar file, and using its full-path to install it works, but I want it to be inside my jar.

Upvotes: 1

Views: 915

Answers (2)

Keerthivasan
Keerthivasan

Reputation: 12890

AFAIK,I don't think you can do install it directly, since it is wrapped inside an artifact. Why don't you have it separate since you need to get it installed anyway.Give them as two jars where both should be placed in the same location. i think this will help. By default, JVM will look for the jar in the current directory

Upvotes: 1

helderdarocha
helderdarocha

Reputation: 23627

You can try this declaring your dependencies in the Manifest.mf file:

Class-path: dependency1.jar dependency2.jar

See more here: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Upvotes: 0

Related Questions