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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:30:36+00:00 2026-05-25T17:30:36+00:00

I am currently putting a program into a .jar, and have difficulties telling it

  • 0

I am currently putting a program into a .jar, and have difficulties telling it where to get its data from. The data was inside of a file in the project, and I am sure that it is located in the jar as well. But I have no clue on how to get a path into a jar.

I found the getClass().getClassLoader().getResourceAsStream() method online to get an input stream into the jar, but since I used FileReaders all the time, I dont know what to do with it as well..

I`d be very thankful for any help.

Edit:

Here is a picture of how the directory is organized:
The console displays a solution, since everything actually runs

My command window shows what happens if I run the .jar. Nullpointer in line 30. I tried it with and without .getClassLoader(), it just wont find it.
Here is the inside of the jar:

again, app is where the class files are in. Hence, via class.getResource.. I should be able to search in DataPackeg. Man, this is wearing me out.

  • 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-25T17:30:37+00:00Added an answer on May 25, 2026 at 5:30 pm

    A key concept to understand is that files don’t exist inside of jars. You must instead get your data as a read-only resource, and you will need to use a path that is relative to path of your class files.

    If you’re still stuck, you may need to tell us more specifics about your current program, its structure, what type of data you’re trying to get, where it’s located in the jar file, and how you’re trying to use it.

    For instance, say your package structure looked like this:

    enter image description here

    So the class file is located in the codePackage package (this is Eclipse so the class files live in a universe parallel to the java files), and the resource’s location is in the codePackage.images package, but relative to the class file it is the images directory, you could use the resource like so:

    package codePackage;
    
    import java.awt.image.*;
    import java.io.*;
    import javax.imageio.*;
    import javax.swing.*;
    
    public class ClassUsesResources {
       private JLabel label = new JLabel();
    
       public ClassUsesResources() {
          try {
             BufferedImage img = ImageIO.read(getClass().getResourceAsStream(
                   "images/img001s.jpg"));
             ImageIcon icon = new ImageIcon(img);
             label.setIcon(icon);
    
             JOptionPane.showMessageDialog(null, label);
          } catch (IOException e) {
             e.printStackTrace();
             System.exit(-1);
          }
       }
    
       public static void main(String[] args) {
          new ClassUsesResources();
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a project I'm currently working for, we're considering putting system() into php.ini's disable_functions
I'm using (GNU) Make in my project. I'm currently putting one makefile per directory
Currently we have a project with a standard subversion repository layout of: ./trunk ./branches
I'm currently putting together some changes in our data model which include changing a
I'm currently putting the final touches on my program and need an icon set
I'm currently putting an HTML site into Expression Engine. The site uses the body
I'm writing a basic program that copies a string from an existing text file
I have this method that I'm currently putting in each page I make, I
Currently my application takes in a text file/files, parses them into another file type
I am currently putting together a rails-based web application which will only serve and

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.