Advertisement
Gamebuster

TrimmedProxy.class

Aug 30th, 2017
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. public abstract class Proxy{
  2.    
  3.     public void preInit(FMLPreInitializationEvent e){
  4.         registerJFXToClasspath();
  5.     }
  6.  
  7.     private void registerJFXToClasspath() {
  8.         Main.LOGGER.info("Adding JRE dependencies to classpath that are not in the classpath");
  9.         String path = System.getProperty("java.home");
  10.         String jfxrt = path + "/lib/ext/jfxrt.jar";
  11.         String jfxswt = path + "/lib/jfxswt.jar";
  12.         addToClassPath(new File(jfxrt));
  13.         addToClassPath(new File(jfxswt));
  14.     }
  15.    
  16.     private void addToClassPath(File f){
  17.         try {
  18.             JarFile jarFile = new JarFile(f);
  19.             Enumeration<JarEntry> e = jarFile.entries();
  20.             URL url = new URL("jar:file:" + f.getAbsolutePath() +"!/");
  21.             LaunchClassLoader lcl = Launch.classLoader;
  22.             lcl.addURL(url);
  23.             while (e.hasMoreElements()){
  24.                 JarEntry entry = e.nextElement();
  25.                 if(entry.isDirectory() || !entry.getName().endsWith(".class")){
  26.                     continue;
  27.                 }
  28.                 String className = entry.getName().substring(0, entry.getName().length() - 6);
  29.                 className = className.replace('/', '.');
  30.                 try{
  31.                     lcl.loadClass(className);
  32.                 }
  33.                 catch(ClassNotFoundException | NoClassDefFoundError e2){
  34.                     Main.LOGGER.error("Could not add " + className + " to classpath");
  35.                 }
  36.                 Main.LOGGER.info("Added " + className + " to classpath");
  37.             }
  38.             jarFile.close();
  39.            
  40.         } catch (IOException e) {
  41.             throw new RuntimeException(e);
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement