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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:24:42+00:00 2026-05-18T11:24:42+00:00

I’m having some issues wrapping my head around the concept of classloading, I’ve been

  • 0

I’m having some issues wrapping my head around the concept of classloading, I’ve been programming for a little while now but I’m relatively knew to how classloading works, I’ve gone through a couple of examples and read about the details behind classloading and classes themselves, while I understand it to a certain extent theres a concept thats escaping me and seems rather hard to put into search-friendly terms.

Essentially, I’m trying to create ‘guilds’ for a gamemode I’ve been developing for Minecraft, these guilds lie in their own classes and are loaded up with the game at startup or whenever the method ‘reloadGuildFiles()’ is issued. I develop these classes by first exporting the main application and adding it to the classpath of the guild being created as well as the main applications dependencies.

Here is the ‘reloadGuildFiles’ method.

public void reloadGuildFiles() {
  unloadGuildFiles();

  synchronized ( _sync ) {
   System.out.println( "Loading guild class files." );

   File guildDataSourceDirectory = new File( "Prospect/Guilds/" );

   URLClassLoader urlcl = null;

   try {
    urlcl = URLClassLoader.newInstance( new URL[] { guildDataSourceDirectory.toURI().toURL() }, Thread.currentThread().getContextClassLoader() );
   } catch ( Exception e ) {
    e.printStackTrace();
    return;
   }

   if ( urlcl == null )
    return;

   for ( File guildDataFile : guildDataSourceDirectory.listFiles() ) {
    if ( !guildDataFile.getName().endsWith( ".class" ) ) {
     System.out.println( "Skipping " + guildDataFile.getName() );
     continue;
    }

    try {
     String className = guildDataFile.getName().substring( 0, guildDataFile.getName().lastIndexOf( "." ) );

     System.out.println( "Loading: " + className + "\n" +
       "\tfrom: " + guildDataFile.getPath() );

     Class<?> clazz = urlcl.loadClass( className );

     Object object = clazz.newInstance();

     if ( object instanceof Guild == false ) {
      System.out.println( "Object loaded is not an instance of Guild." );
      continue;
     }

     Guild guild = ( Guild ) object;

     if ( _guildMap.containsKey( guild.getName() ) ) {
      System.out.println( "Duplicate guild names in guild map: " + guild.getName() );
      continue;
     }

     _guildMap.put( guild.getName(), guild );
     guild.onGuildLoaded();
    } catch ( Exception e ) {
     System.out.println( e.getMessage() );
     e.printStackTrace();
     continue;
    }
   }
  }
 }
}

Here is the Guild class contained within the main application.

public abstract class Guild {
 public abstract String getName();

 public void onGuildLoaded() {
  System.out.println( "Loaded: " + getName() );
 }
}

Here is the class I am trying to classload

public class Warrior extends Guild {
 public String getName() {
  returns "Warrior";
 }
}

Here is the error it is giving me:

java.lang.NoClassDefFoundError: Guild
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.net.FactoryURLClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at GuildManager.reloadGuildFiles(GuildManager.java:53)
        at Prospect.enable(Prospect.java:64)
        at PluginLoader.load(PluginLoader.java:205)
        at PluginLoader.reloadPlugin(PluginLoader.java:189)
        at je.d(je.java:1196)
        at je.a(je.java:430)
        at bg.a(SourceFile:24)
        at bh.a(SourceFile:218)
        at je.a(je.java:56)
        at dp.a(SourceFile:85)
        at net.minecraft.server.MinecraftServer.h(SourceFile:267)
        at net.minecraft.server.MinecraftServer.run(SourceFile:208)
        at bw.run(SourceFile:482)
Caused by: java.lang.ClassNotFoundException: Guild
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at java.net.FactoryURLClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 25 more

From what I can gather and from what I understand, even though the main application is on the build path of the class to be loaded, the classloader does not recognize the class Guild. I think I need to try and make the classloader recognize the Guild class contained in the main application, is there anyway to do this or is there something I am clearly doing wrong?

  • 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-18T11:24:42+00:00Added an answer on May 18, 2026 at 11:24 am

    The only possible problem I can see here is that Thread.currentThread().getContextClassLoader() for some reason produces a classloader that can’t be used to access Guild class.

    Try this instead:

    urlcl = URLClassLoader.newInstance( new URL[] { guildDataSourceDirectory.toURI().toURL() }, Guild.class.getClassLoader()); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.