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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:56:18+00:00 2026-06-13T15:56:18+00:00

Possible Duplicate: load file within a jar Finally, I made my jar file work

  • 0

Possible Duplicate:
load file within a jar

Finally, I made my jar file work almost correctly. Almost, because when I test it and launch just after creating jar file, a picture which is included in the archive appears. But when I move the jar file to any other directory and try to launch – I get an exception regarding missing picture (the application is still working though, but doesn’t display that picture).

This is how it looks in my directory:

[aqv@voland Converter]$ ll
razem 112
-rw-rw-r--. 1 aqv aqv 51673 10-30 20:42 Converter.java
-rw-rw-r--. 1 aqv aqv    23 10-30 20:41 Converter.mf
-rw-rw-r--. 1 aqv aqv  1167 10-30 20:43 GBC.java
-rw-rw-r--. 1 aqv aqv  1023 10-30 20:58 ImagePanel.java
-rw-rw-r--. 1 aqv aqv 44729 10-30 20:35 programHelp.png
-rw-rw-r--. 1 aqv aqv  3713 10-30 20:43 SettingsManager.java
[aqv@voland Converter]$ 
[aqv@voland Converter]$ 

The picture file gets called from ImagePanel, programHelp is a string which is then passed to proper method:

public ImagePanel() {

    programHelp = "programHelp.png";

    try {
        helpImage = ImageIO.read(new File(programHelp));
    } catch (IOException e) {
        e.printStackTrace();
    }
}

As you can see, there are no directories specified, so I guess the main class should look for the image in the jar’s main directory, shouldn’t it?

I create the jar file in the following way (after compiling the files, of course):

[aqv@voland Converter]$ jar cvfm Converter.jar Converter.mf *.class *.png
[aqv@voland Converter]$ 

The picture file is visible inside the jar archive, among class files. My question: what is wrong with the image file placement in this case?

  • 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-06-13T15:56:19+00:00Added an answer on June 13, 2026 at 3:56 pm

    Your program is only working by coincidence – it is actually loading the PNG from outside the JAR. You could test this by temporarily renaming the image but keeping the JAR in the directory, if you like.

    To load resources from within a JAR, you need to use one of the getResource() methods of a Class object, rather than loading files directly.

    You can still use ImageIO to load the data from the stream returned by getResourceAsStream(), for example. Something like the following:

    InputStream is = this.getClass().getResourceAsStream("my.png");
    helpImage = ImageIO.read(is);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: XNA - File not found problem Here I am trying to load
Possible Duplicate: Problem when loading php file into variable (Load result of php code
Possible Duplicate: Classpath including JAR within a JAR I would like to know if
Possible Duplicate: Load local HTML file in a C# WebBrowser I´m creating program in
Possible Duplicate: Load an SWF into a WebView I have a .swf file and
Possible Duplicate: Ruby 1.9 - no such file to load 'win32/open3' I am having
Possible Duplicate: I want to load the data from XML file and show in
Possible Duplicate: android reading from a text file So I need to load text,
Possible Duplicate: .NET file system wrapper library I would like to write a test
Possible Duplicate: Problem when loading php file into variable (Load result of php code

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.