Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3596774
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:01:56+00:00 2026-05-18T20:01:56+00:00

I have a jar embedded in a bundle that needs to fetch a resource

  • 0

I have a jar embedded in a bundle that needs to fetch a resource packaged with it like so:

MyBundle
  -\ src
  -\lib
    -\MyEmbeddedJar
      -\src
        -\SomeClass
      -\someResource.xml

I am trying to access ‘someResource.xml’ from ‘SomeClass’ like so:

SomeClass.class.getResource( "someResource.xml" ); 

But I’ve had no luck. I’ve tried several variations with the CWD appended (eg: ‘./someResource.xml’) but I just can’t get this resource to load.

I know that the “right” way is to use Activator to get hooks back to the proper classloader, but the embedded jar can be used in other projects, so I’d hate to have to add OSGi specific code to it just to get it to play nice with OSGi.

Is there any other way to load resources in OSGi agnostically of OSGi?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T20:01:56+00:00Added an answer on May 18, 2026 at 8:01 pm

    I Assume that SomeClass is inside the embedded jar (say, somejar.jar), and someResource.xml is in the outer jar, in a lib directory.

    In this case, there is no way to get to that in a non-OSGi context. Let’s look at both situations in isolation.

    In OSGi

    Your someResource.xml should very well be reachable using the regular (non-OSGi specific) resource loading mechanisms, provided that it is reachable from the Bundle-ClassPath. For instance, if you have the following manifest header,

    Bundle-ClassPath: ., somejar.jar
    

    you will be able to get to your resource using "lib/someResource.xml".
    Notice the dot on the classpath: this means you can reach classes and resources from the root of the jar. If you forget that, you will only be able to get to classes and resources inside somejar.jar.

    Not using OSGi

    If you’re not using OSGi, there is no (reasonably simple) way to get to classes and resources inside of the inner jar that I know of.

    Your options

    Depending on what you want your bundle to look like, you have two options now.

    1. Is it really necessary that SomeClass is in an embedded jar? If so, you’re at a loss, and you jar will only work using OSGi.
    2. If you have the option to ‘unpack’ somejar.jar into your jar, you subvert the problem, and your jar can work in both situations.

    Personally, I’d pick option 2.: unless you have resources that might overwrite each other when you ‘merge’ the jars, it is no problem at all to have a slight mess of resources inside your bundle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jar embedded in a bundle that needs to fetch a resource
I have a .jar file that i've placed in my D:\Coldfusion8\wwwroot\web-inf\lib\ directory. The file
I have a groovy script that needs a library in a jar. How do
I have a GWT application that includes an embedded applet. I would like to
I have a jar file that has a file named client.ts in (when viewing
I have an application that I'm trying to wrap into a jar for easier
I have a javadoc doclet that requires an additional jar file to be on
How do I take a jar file that I have and add it to
I have a Java app that has an embedded Derby database (no hibernate though).
I have a jar file named xyz.jar that have the file abc.xml and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.