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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:46:22+00:00 2026-05-24T03:46:22+00:00

Our java application relies on some resources which are available on a network share.

  • 0

Our java application relies on some resources which are available on a network share. This network share is located on the classpath, and the resources are read at runtime using MyClass.class.getResourceAsStream("/myfile.jpg").

java -Djava.class.path=\\myserver\myshare:C:\myjar.jar MainClass

When the share is available at startup, everything runs smoothly. Image and properties files which are located in the share can be read using getResourceAsStream(). However, if the share is not online when the application starts, even if the share comes online before any resources are read, they cannot be read using getResourceAsStream().

Doing some digging using eclispse + decompiler, I noticed one difference. The default classloader inherits from URLClassLoader, and its ucp member (URLClassPath) contains a list of URLClassPath.Loader instances. In the first scenario, it contains a URLClassPath.FileLoader and a URLClassPath.JarLoader. In the second scenario, it only contains a jar loader.

It’s like java determines that the classpath entry is invalid and completely discards it.

Why is this? How can I avoid it?

Update
I am unable to change the mechanism by which we are loading resources because of a few reasons:

  1. There are far too many areas which currently load files this way for me change at the moment
  2. There are situations where by the resource is actually being loaded by a third party component

I have no problem creating a custom class loader, I just need some guidance on how to do it.

I tried with this, but was unable to get expected results:

import java.net.URL;
import java.net.URLClassLoader;

public class MyUrlClassLoader extends URLClassLoader {
    public MyUrlClassLoader(ClassLoader parent) {
        super(new URL[0], parent);
        System.out.println("MyUrlClassLoader ctor");
    }

    @Override
    protected Class<?> findClass(String name) throws ClassNotFoundException {
        System.out.println("url find class " + name);
        return super.findClass(name);
    }

    @Override
    public Class<?> loadClass(String name) throws ClassNotFoundException {
        System.out.println("url load class " + name);
        return super.loadClass(name);
    }

    @Override
    public URL getResource(String name) {
        System.out.println("url get resource " + name);
        return super.getResource(name);
    }
}


import java.net.URL;

public class ClassLoaderMain {
    public static void main(String[] args) throws ClassNotFoundException {
        URL url = ClassLoaderMain.class.getResource("/myfile.txt");
        System.out.print("Loaded? ");
        System.out.println(url != null);

        System.out.println(ClassLoaderMain.class.getClassLoader().toString());
        System.out.println(MyUrlClassLoader.class.getClassLoader().toString());
        System.out.println(FakeClass.class.getClassLoader().toString());
    }
}

When I run java -cp . -Djava.system.class.loader=MyUrlClassLoader ClassLoaderMain

This outputs:

MyUrlClassLoader ctor
url load class java.lang.System
url load class java.nio.charset.Charset
url load class java.lang.String
url load class ClassLoaderMain
Loaded? true
sun.misc.Launcher$AppClassLoader@923e30
sun.misc.Launcher$AppClassLoader@923e30
sun.misc.Launcher$AppClassLoader@923e30

So my class loader is being created, and load class is being called, but it doesn’t appear to be the class loader for the classes it is loading?

  • 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-24T03:46:23+00:00Added an answer on May 24, 2026 at 3:46 am

    I ended up resolving this by creating my own ClassLoader, deriving from URLClassLoader.

    import java.io.File;
    import java.net.MalformedURLException;
    import java.net.URI;
    import java.net.URL;
    import java.net.URLClassLoader;
    import java.util.ArrayList;
    import java.util.List;
    
    public class CustomClassLoader extends URLClassLoader {
    
        public CustomClassLoader(ClassLoader parent) {
            // System classloader will filter inaccessible URLs. 
            // Force null parent to avoid using system classloader.
            super(createURLReferences(), null);
        }
    
        /**
         * Build an array of URLs based on the java.class.path property.
         * @return An array of urls to search for classes.
         */
        private static URL[] createURLReferences() {
            String classpath = System.getProperty("java.class.path");
            String[] classpathEntries = classpath.split(System.getProperty("path.separator"));
            List<URL> urls = new ArrayList<URL>();
            for (String classpathEntry : classpathEntries) {
                File classpathFile = new File(classpathEntry);
                URI uri = classpathFile.toURI();
                try {
                    URL url = uri.toURL();
                    urls.add(url);
                } catch (MalformedURLException e) {
                    System.out.println("Ignoring classpath entry: " + classpathEntry);
                }
            }
    
            return urls.toArray(new URL[urls.size()]);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've set up ehcache on our Java application, which uses Spring and Hibernate. However,
After refactoring some service-layer classes in our java web application, i was asking myself
I have a J2EE java application which processes SOAP requests. In our production environment
Currently our Java application uses the values held within a tab delimited *.cfg file.
Part of our java application needs to run javascript that is written by non-developers.
Our Java code (not the test code) reads files from the current directory, which
I currently work on a Java web application that has relies on a permissions
Our Java application has about 100 classes mapped to a database (SQL Server or
On one of our Java application screens, we want to display data loaded from
We are extending our java application to support plugins. Part of that includes keeping

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.