Properly adding asm dependecy (or any other dependency) to you library

I’m currently writing a library to reduce boilerplate code.
Instead of using registerMethod and reflection to process all events I thought it might be faster to use asm to create create Runnables instead of using reflection.

The problem is the following:
It seems Processing uses the library folder of every library as classpath. Therefore if 2 libraries use the same library as dependency processing can’t process the import anymore.
How would one go around this problem?

1 Like

A thing I tried to do is to dynamically load the classes that are not loaded from a backup of the library not on the classpath. This is done hoping that once my library uses asm the class will be loaded and no ClassNotFoundException will be thrown. This is my current code to do this:


import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
public class Injector {
	@SuppressWarnings({ "resource"})
	public static void assertLoaded(String jar,String... names) {
		File jarFile=new File(jar);
		URLClassLoader ucl;
		try {
			URL fileURL=jarFile.toURI().toURL();
			String jarURL="jar:"+fileURL+"!/";
			URL urls[]={new URL(jarURL)};
			ucl=new URLClassLoader(urls,Thread.currentThread().getContextClassLoader());
		}
		catch(MalformedURLException e) {
			throw new RuntimeException(e);
		}
		
		for(String name:names) {
			try {
				Class loadedcl=Class.forName(name,true,ucl);
				//System.out.println(loadedcl);
			}catch(ClassNotFoundException e) {
				throw new RuntimeException(e);
			}
		}
	}
}

The problem is: it doesn’t seem to work at all. Whenever I use Class.forName to get one of the classes I (supposedly successfully) loaded it can’t find it anymore.