Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Proxy{
- public void preInit(FMLPreInitializationEvent e){
- registerJFXToClasspath();
- }
- private void registerJFXToClasspath() {
- Main.LOGGER.info("Adding JRE dependencies to classpath that are not in the classpath");
- String path = System.getProperty("java.home");
- String jfxrt = path + "/lib/ext/jfxrt.jar";
- String jfxswt = path + "/lib/jfxswt.jar";
- addToClassPath(new File(jfxrt));
- addToClassPath(new File(jfxswt));
- }
- private void addToClassPath(File f){
- try {
- JarFile jarFile = new JarFile(f);
- Enumeration<JarEntry> e = jarFile.entries();
- URL url = new URL("jar:file:" + f.getAbsolutePath() +"!/");
- LaunchClassLoader lcl = Launch.classLoader;
- lcl.addURL(url);
- while (e.hasMoreElements()){
- JarEntry entry = e.nextElement();
- if(entry.isDirectory() || !entry.getName().endsWith(".class")){
- continue;
- }
- String className = entry.getName().substring(0, entry.getName().length() - 6);
- className = className.replace('/', '.');
- try{
- lcl.loadClass(className);
- }
- catch(ClassNotFoundException | NoClassDefFoundError e2){
- Main.LOGGER.error("Could not add " + className + " to classpath");
- }
- Main.LOGGER.info("Added " + className + " to classpath");
- }
- jarFile.close();
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement