Jump to content

Recommended Posts

Posted

I'm developing a coremod. One of the things this mod does is load all the classes implementing a certain type from a certain package.

 

By default the classloader doesn't recognize a package until it has to load a class from that package. So I force the classloader to be aware of it. In development/eclipse, this works just fine. But once the mod is added into a clean forge jar, the classloader is not finding the package no matter what I do.

 

Some of the things I've tried:

		Class<Module> someModule = Module.class; //should make the classloader aware
	try {
		ClassLoader.getSystemResources("net.*"); //should load the net.sparrow package
	} catch (IOException e2) {
		// TODO Auto-generated catch block
		e2.printStackTrace();
	}
	try {
		Module.class.getClassLoader().loadClass("net.sparrow.module.Module"); //should FORCE the class to load
	} catch (ClassNotFoundException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	Package[] knownPacks = Package.getPackages(); //prints all known packages from the classloader
//note that it does NOT print aynthing from the packages described above (net.sparrow)
	for(int i = 0; i < knownPacks.length; i++) {
		FMLLog.info("Package:" + knownPacks[i], 0);
	}
	ArrayList<Class<?>> moduleList = UtilFile.getClassesForPackage(Module.class.getPackage());
//getPackage() is always returning null.

Posted

Jar editing ? You are doing it wrong. Mod goes in mods folder.

Yes I'm aware, I'm developing a coremod which modifies base mc files

 

What are you even trying to do?

As soon as you do Module.class it already loads the class anyways.

I know, that's what I thought.

 

My mod basically looks for all the .class files in a certain package in the jar. So you just open up the package and iterate through the files, instantiating a new copy of each of them as you go.

 

The problem is that the classloader has not been made aware of the package, and thus refuses to load it. Ok, fair enough, just force the classloader to load a .class file from the package itself (like Module.class) and then it'll load up the package into memory. In the development environment, this works just fine. But as soon as it's simply inserted into a clear .jar file, Forge's classloader fails to pick up the package. I wonder if that's a fault of Forge's or something else.

Posted

GotoLink is ABSOLUTELY RIGHT!

 

Even if it is a core mod that edits base files, it is still a MOD so it goes in the MODS FOLDER. It should then be able to iterate as you are wanting to do. ( Notice I said SHOULD... )

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.