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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:29:06+00:00 2026-06-10T01:29:06+00:00

I’m trying to build a large Java project by building many small, modular projects.

  • 0

I’m trying to build a large Java project by building many small, modular projects. I want each small project to be entirely self contained, holding all of its resources (such as images).

I am using Eclipse. If I configure the build path to add one of the modular projects, the resource references don’t work. The system cannot find the file specified. The same thing occurs if I export a jar and include that in the libraries tab of configure build path.

I’ve done some experimenting, and haven’t been able to figure out a way to get it to work. I’ve tried using source folders for resources and using:

// this works if resource is located in package alongside class file, 
// not where I want it
getClass().getResourceAsStream("resource.abc")

or

new FileInputStream("path/to/resource.abc")

Maybe I’m missing something about how projects are structured. I’ve always been able to get resources to work from a single project within the IDE without any trouble. What is different when you start linking multiple projects or including them as jars?

My ideal structure would be to have another folder, at the same level as the src folder in the root of my project, that would contain all of my resources, separate from source code. This is how it was set up before all the trouble trying to link projects/jars.

  • 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-10T01:29:07+00:00Added an answer on June 10, 2026 at 1:29 am

    This solution worked for me:

    /**
     *
     * @author David
     */
    public class JavaApplication60 {
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        //http://img.viralpatel.net/java-cup-logo.png
    
        //located in a package not in the current one
        URL url = new JavaApplication60().getResource("/javaapplication60/newpackage/java-cup-logo.png");
        System.out.println(url.getPath());
        //located in same package
        url = new JavaApplication60().getResource("/javaapplication60/java-cup-logo.png");
        System.out.println(url.getPath());
    }
    
    public InputStream getResourceAsStream(String name) {
        name = resolveName(name, this.getClass());
        ClassLoader cl = getClass().getClassLoader();
        if (cl == null) {
            return ClassLoader.getSystemResourceAsStream(name); // A system class.
        }
        return cl.getResourceAsStream(name);
    }
    
    public java.net.URL getResource(String name) {
        name = resolveName(name, this.getClass());
        ClassLoader cl = getClass().getClassLoader();
        if (cl == null) {
            return ClassLoader.getSystemResource(name);  // A system class.
        }
        return cl.getResource(name);
    }
    
    
    /*
     * The resolveName method adds a package name prefix if the name is not
     * absolute, and removes any leading "/" if the name is absolute. It is
     * possible, though uncommon, to have classes in diffent packages sharing
     * the same resource.
     */
    private String resolveName(String name, Object clazz) {
        if (name == null) {
            return name;
        }
        if (!name.startsWith("/")) {
            Class c = clazz.getClass();
            while (c.isArray()) {
                c = c.getComponentType();
            }
            String baseName = c.getName();
            int index = baseName.lastIndexOf('.');
            if (index != -1) {
                name = baseName.substring(0, index).replace('.', '/') + "/" + name;
            }
        } else {
            name = name.substring(1);
        }
        return name;
    }
    }
    

    My package structure looked like this:

    My package structure for above code

    References:

    • Location-Independent Access to Resources
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
We're building an app, our first using Rails 3, and we're having to build
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.