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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:20:14+00:00 2026-06-18T03:20:14+00:00

I would like to know how to create a runnable JAR with resources (pictures,

  • 0

I would like to know how to create a runnable JAR with resources (pictures, pdfs) in a resource folder either inside or outside the source package (ie /src/resources/images/ or /resources/images/) in Eclipse. Currently, i have my resources inside the source folder of my eclipse project, but I’ve also tried it inside its own folder in the package. The program builds and executes fine in eclipse, but when I go to export as a runnable jar, I keep getting a file not found exception when I run it on the desktop. I’m declaring my files with a string like this

private String file =  "src/resources/orderForm.pdf";

I understand that I should user getResourceAsStream(), but due to some constraints, I can’t (has to do with how files are saved, I’m reading in whole pdf files, not as streams) so I’m wondering how to get my files into the correct location in the jar. If i unpack it after I’ve made it they always show up in the top level, outside of the folders. Here is a screen shot of my current project structure. For the sake of saying it, this project works fine in eclipse, also in the java build properties, the source folder is in the build path along with all subfolders, I also tried doing the same with the empty resources folder in an earlier test.
enter image description here

  • 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-18T03:20:16+00:00Added an answer on June 18, 2026 at 3:20 am

    You will need to do the getResourceAsStream, and make sure that the pdfs get built into the jar. Since you have them in the source folder, they should.

    Assuming you have the pdf under src/resources/orderForm.pdf, it will end up in the jar file as /resources/orderForm.pdf. You would open a resource stream for /resources/orderForm.pdf.

    If you must have a honest to goodness file, then you would need code that reads the PDF as a resource stream, FileOutputStreams it out to a temp file, then uses the file. Or, you simply cannot package the pdfs in the jar.

    public class PDFWriter {
    
    public static final String testDir = "C:\\pdftest\\"; 
    public static final String adobePath = "\"C:\\Program Files\\Adobe\\Reader 10.0\\Reader\\AcroRd32.exe\"";
    
    public static void main(String[] args){
    
        try {
            new PDFWriter().run();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public void run() throws Exception {
        InputStream in = this.getClass().getResourceAsStream("/resources/test.pdf");
        new File(testDir).mkdirs();
        String pdfFilePath = testDir + "test.pdf";
        FileOutputStream out = new FileOutputStream (pdfFilePath);
        byte[] buffer = new byte[1024];
        int len = in.read(buffer);
        while (len != -1) {
            out.write(buffer, 0, len);
            len = in.read(buffer);
        }
        out.close();
    
        Runtime rt = Runtime.getRuntime();
        String command = adobePath + " " + pdfFilePath;
        rt.exec(command);
    }
    
    }
    

    The only reason the file way works at all in eclipse is because the bin folder is a real folder, but when you build the thing, it all gets zipped up into a jar.

    Maybe a bit of confusion over source folders. If you have a source folder called ‘src’, the package structure under it does not contain “src”. src/net/whatever/Class.java will turn into net/whatever/Class.class when build.

    So, you could create a second source folder called ‘rsrc’ (resources), and under this put your resources/order.pdf. rsrc/resources/order.pdf will become resources.order.pdf when you build the jar.

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

Sidebar

Related Questions

I would like to know how to create django relation model for user, folder,
I would like to know how to create a TextView inside of a thread:
I would like to know how to create a linked list of linked lists.
i would like to know how to create a hidden type input box and
I would like to know how to create a computed observable array. In my
I would like to know how to create a php function that can be
I would like to know how to create a rounded corners on a table
Hi I would like to know how to create a dll that is written
I'm an amateur web developer and I would like to know how to create
I would like to know how can I create a regexp to match the

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.