Hey ,
My Problem is that the ClassLoader in my Programm only works when I debug my Programm but i don't know why?
I tried so many Thinks but yeah nothing better.
My Code:
String userPath = System.getProperty("user.home"); File clientLocation = new File(userPath + "\\AppData\\Roaming\\.minecraft\\versions\\MCP"); File f2 = new File(clientLocation.getPath() + "\\plugins"); if (!f2.exists()) { f2.mkdir(); } File f1 = new File(clientLocation.getPath() + "\\plugins\\pluginMeta"); if (!f1.exists()) { f1.mkdir(); } File[] arrayOfFile; int j = (arrayOfFile = new File(clientLocation.getPath() + "\\plugins").listFiles()).length; for (int i = 0; i < j; i++) { File file = arrayOfFile[i]; if (file.getName().endsWith(".jar")) { File authorizedJarFile = file; ClassLoader authorizedLoader = null; try { authorizedLoader = URLClassLoader.newInstance(new URL[] { authorizedJarFile.toURL() }); } catch (MalformedURLException e) { e.printStackTrace(); } try { File pluginYML = new File(clientLocation.getPath() + "\\plugins\\pluginMeta\\" + file.getName().replace(".jar", "") + ".yml"); if (!pluginYML.exists()) { pluginYML.createNewFile(); } JarFile jarFile = new JarFile(authorizedJarFile); ZipEntry entry = jarFile.getEntry("plugin.yml"); InputStream is = jarFile.getInputStream(entry); Files.copy( is, pluginYML.toPath(), new CopyOption[] { StandardCopyOption.REPLACE_EXISTING }); IOUtils.closeQuietly(is); FileConfiguration cfg = new FileConfiguration(pluginYML); Class c = authorizedLoader.loadClass(cfg.getString("main")); Plugin authorizedPlugin = (Plugin)c.newInstance(); plugins.add(authorizedPlugin); authorizedPlugin.setName(cfg.getString("name")); authorizedPlugin.setAuthor(cfg.getString("author")); authorizedPlugin.setVersion(cfg.getString("version")); authorizedPlugin.onEnable(); System.out.println("[" + Date.getDate() + "] Enabling " + authorizedPlugin.getName() + " v" + authorizedPlugin.getVersion() + " by " + authorizedPlugin.getAuthor()); } catch (IOException|InstantiationException|IllegalAccessException e1) { } } }
So I mean this code works perfectly when I debug my Programm, but when i run it normal, it says 'ClassCastException'.
Please help D: