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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:21:39+00:00 2026-06-05T02:21:39+00:00

I seem to be having a problem with loading classes in a module loader

  • 0

I seem to be having a problem with loading classes in a module loader for an application I’m developing. Basically, all classes I’m going to be loading with it extend another class, which is located in a package in the actual application. For our purposes, we’ll call it Module. Modules are located in a separate folder outside the actual application.

The loader iterates through a folder and executes the loadFile() method on any file with the extension .class. All classes have the package declaration as the Module class, as well as the extends Module declaration in the class header.

This is the loadFile() method, header and exception clauses excluded:

String fileName = file.getName();
String className = fileName.replace(".class", ""); //Strips extension
Class<?> aClass = Class.forName(className, true, new URLClassLoader(new URL[] { file.toURI().toURL() }));
Class<? extends Module> modClass = aClass.asSubclass(Module.class);
return modClass.getConstructor().newInstance();

I keep getting a ClassNotFoundException on the third line. And past that, if it ClassNotFoundException weren’t thown, would all dependencies be resolved?

  • 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-05T02:21:40+00:00Added an answer on June 5, 2026 at 2:21 am

    From the documentation for URLCLassLoader:

    This class loader is used to load classes and resources from a search path of URLs referring to
    both JAR files and directories. Any URL that ends with a ‘/’ is assumed to refer to a directory.
    Otherwise, the URL is assumed to refer to a JAR file which will be opened as needed.

    So, you must use URLs for either directories or .jars

    Two solutions:

    1. Force your users to give you .jar files, including a manifest of some sort inside with the classname that they wish to be loaded. This approach is used by the Bukkit developers. Having used this method in the past, the dependencies should all be packaged in the .jar file and thus in the URLClassLoader’s search path and able to be loaded.
    2. Use the URL of the file’s directory, and search that directory for .class files. I’m not sure if dependencies will be loaded using this method.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to be having a problem with checking for list equality. In my
I seem to be having a problem with my footer growing to 100% width
Okay, I seem to be having a problem. I'm trying to create a twicker
I'm having a problem in ruby and I can't seem to find the solution
I'm having a problem and can't seem to find the solution.. int linearSearch(nodeptr list,char
I'm having a problem with my site http://artygirl.co.uk/pixie/about/ I can't seem to get the
I'm really having a problem finding out how to fix this. I cannot seem
In Chrome v17.0.963.79 on Windows 7, I seem to be having an inexplicable problem
I'm having trouble with MySQL or Python and can't seem to isolate the problem.
i having problem in converting this C# code into VB.net. The loadLecturer seem to

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.