diff options
author | nea <nea@nea.moe> | 2023-11-01 14:02:59 +0100 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-11-01 14:02:59 +0100 |
commit | d5253dc5c3ae7b2cc1fcb96780e43b929a449eb4 (patch) | |
tree | 478973510c9d7eda999b8321a07f34691ba56e8b /src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java | |
download | ModernJavaLauncher-d5253dc5c3ae7b2cc1fcb96780e43b929a449eb4.tar.gz ModernJavaLauncher-d5253dc5c3ae7b2cc1fcb96780e43b929a449eb4.tar.bz2 ModernJavaLauncher-d5253dc5c3ae7b2cc1fcb96780e43b929a449eb4.zip |
Initial commit
Diffstat (limited to 'src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java')
-rw-r--r-- | src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java b/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java new file mode 100644 index 0000000..09f2368 --- /dev/null +++ b/src/main/java/moe/nea/modernjava/launch/util/ClassLoaderManipulations.java @@ -0,0 +1,31 @@ +package moe.nea.modernjava.launch.util; + +import net.minecraft.launchwrapper.Launch; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.MalformedURLException; +import java.net.URL; + +public class ClassLoaderManipulations { + + public static void addToParentClassLoader(File file) { + try { + addToParentClassLoader(file.toURI().toURL()); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + + public static void addToParentClassLoader(URL file) { + try { + Launch.classLoader.addURL(file); + ClassLoader parentClassLoader = Launch.classLoader.getClass().getClassLoader(); + Method addUrl = parentClassLoader.getClass().getDeclaredMethod("addURL", URL.class); + addUrl.setAccessible(true); + addUrl.invoke(parentClassLoader, file); + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} |