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 563935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:42:46+00:00 2026-05-13T12:42:46+00:00

I have source code: private Image getImage(String path, ClassLoader loader) { InputStream image =

  • 0

I have source code:

private Image getImage(String path, ClassLoader loader) {
    InputStream image = null;
    try {
        image = loader.getResourceAsStream(path);
        return new Image(PlatformUI.getWorkbench().getDisplay(), image);
    } finally {
        if (image != null) {
            try {
                image.close();
            } 
            catch (IOException e) {
                //OK
            }
        }
    }
}

On my computer this code works perfect. But, on virtual machine line:

loader.getResourceAsStream(path);

always returns null. Why?

EDIT:

Path is a relative path. For example: icons/tools/device.png.
Application which I develop contains more than ten projects. I use Eclipse IDE. All projects have structure:

  • com.pkg.name – folder with classes icons
  • folder with icons and others files

Jar files have this structure too.

On my computer applications works perfect. On virtual machine (Windows Server(64-bit)) application can’t loads images from Jar file.

  • 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-13T12:42:46+00:00Added an answer on May 13, 2026 at 12:42 pm

    If path is a relative path, then it should work, as long as the image resource has been copied along with the class files (as Itay already mentioned) and the folder or jar that contains the image resource is on the classpath (do you use CLASSPATH or -cp to specify the classpath? If you rely on CLASSPATH, make sure, the this environment variable is properly set for the user that executes the application)

    If it is an absolute path, double check if it is valid on the target VM.

    so basically, for a folder structure like

    ./classes
    ./images
    ./libs
    

    the command java -cp classes;images;libs/* my.app.Application should work (java 1.6 – in older versions the wildcard is not allowed), assuming a path value like images/myImage.jpg.

    Just another thought, the classpath delimter is ; on Windows and : on unix. That might be a problem if you prepared the app on a unix-type environment.

    Edit

    Do you read the image from the same library as you actual classfile? Then please give this a try:

    this.getClass().getResourceAsStream(path)
    

    Edit

    OK, it’s OSGi. So there are some more reasons why the application works from inside the eclipse IDE but not when deployed as a RCP application. I think it has nothing to do with the target environment.

    In OSGi every bundle has it’s own classloader and a class from bundle1 will not be able to see classes from bundle2 unless the packages are properly exported. This is true for resources as well. I guess that the image is stored in a different bundle. I don’t know which classloader is passed to the getImage method, but that classloader definitely can’t see the resource file.

    It might work inside eclipse, especially if you add the projects to each others build paths.

    After you’ve built the product, you said it fails (partially) on the VM but does the same product show the image on the local machine (outside eclipse)?

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

Sidebar

Related Questions

I have a source code that is needed to be converted by creating classes,
I have some source code to get the file name of an url for
I have this source code from 2001 that I would like to compile. It
I have standard source code package under Linux which requires to run ./configure make
I have this source code: idx=0 b=plt.psd(dOD[:,idx],Fs=self.fs,NFFT=512) B=np.zeros((2*len(self.Chan),len(b[0]))) B[idx,:]=20*log10(b[0]) c=plt.psd(dOD_filt[:,idx],Fs=self.fs,NFFT=512) C=np.zeros((2*len(self.Chan),len(b[0]))) C[idx,:]=20*log10(c[0]) for idx
I have java source code in a text file. There has to be entered
I have a problem with 2D transformation program I have the source code import
I have an installer for which I don't have any source code. I need
Let's say I have created a program in C/C++ and have a source code.
I have an application I need to analyze. I have the source code here.

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.