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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:12:05+00:00 2026-05-13T18:12:05+00:00

I made a java application.and bundled all classes in jar file..wen i run the

  • 0

I made a java application.and bundled all classes in jar file..wen i run the project from netbeans my app is running successfully..but wen i place my .jar file at another place and run from there..i am not getting the icons used by my application..In the code i get my icons from images directory present in project folder.

Now,i wanted to know how can we present these image files to the end user (like we present .jar file).Thanks in advance

  • 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-13T18:12:06+00:00Added an answer on May 13, 2026 at 6:12 pm

    It seems like there are two questions here:

    1. How do I get NetBeans to include an image file in the jar produced when I build my project?

    2. How do I access an image file from a jar?

    This answer applies to NetBeans 6.8 and addresses both of the subquestions.

    Assume that you have an ant based Java Application Project.

    Here is the ‘Files’ view of the project

    JP
    + images
      + test.jpg
    + nbproject
    + src
      + jp
        + Main.java
    + test
    + build.xml
    + manifest.mf
    

    Inside your Main.java you have code like this:

    public static void main(String[] args) throws IOException {
        // find the file in the file system.. probably not a good idea
        File f = new File("images/test.jpg");
        System.out.println(f.getCanonicalPath()+" "+f.exists());
    

    When you run this project from inside NB you get this output:

    /export/home/vkraemer/NetBeansProjects/JavaApplication2/images/test.jpg true
    

    When you run the code packed into the jar, you get something like this:

    bash-3.2$ pwd
    /export/home/vkraemer/nbhg/web-main
    bash-3.2$ java -jar /export/home/vkraemer/NetBeansProjects/JavaApplication2/dist/JavaApplication2.jar
    /export/home/vkraemer/nbhg/web-main/images/test.txt false
    

    To get something better when the jar is executed, you need to do the following:

    Add the images directory as a source root for you project.

    Right click on the project and select the Properties item. A dialog will appear.

    Select ‘Sources’ in the list that is on the left side of the dialog. This will change the content of the panel on the right side of the dialog.

    Press the ‘Add Folder…’ button that appears next to the ‘Source Package Folders’ table. A FileChooser will appear.

    Use this chooser to select the images folder and press the OK button. An entry for the images folder will be added table.

    Use the OK button on the Project Properties dialog to accept the changes and dismiss the dialog.

    Change your code to use Class.getResource().

    public static void main(String[] args) throws IOException {
        // find the file in the file system.. probably not a good idea
        File f = new File("images/test.jpg");
        System.out.println(f.getCanonicalPath()+" "+f.exists());
        URL url = Main.class.getResource("/test.jpg");
        System.out.println(url);
    

    When you run the project from inside the IDE, you should see something like this:

    /export/home/vkraemer/NetBeansProjects/JavaApplication2/images/test.jpg true
    file:/export/home/vkraemer/NetBeansProjects/JavaApplication2/images/test.jpg
    

    When you run the code packed into the jar, you will get something like this:

    bash-3.2$ pwd
    /export/home/vkraemer/nbhg/web-main
    bash-3.2$ java -jar /export/home/vkraemer/NetBeansProjects/JavaApplication2/dist/JavaApplication2.jar
    /export/home/vkraemer/nbhg/web-main/images/test.jpg false
    jar:file:/export/home/vkraemer/NetBeansProjects/JavaApplication2/dist/JavaApplication2.jar!/test.jpg
    

    After you get the URL for the test.jpg file, you can use ImageIcon(URL) to create the icon

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

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The other answers are correct. Here is some code you… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer you ruin the noConflict concept by reassigning the jquery to… May 14, 2026 at 9:40 am
  • Editorial Team
    Editorial Team added an answer If you get that particular error, you don't actually have… May 14, 2026 at 9:40 am

Related Questions

No related questions found

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.