It is required to make a class loader from a file for java.
I heard that this is done by overriding the ClassLoader operators, how can this be done?
On the Internet is not one normal instructions.
It is required to make a class loader from a file for java.
I heard that this is done by overriding the ClassLoader operators, how can this be done?
On the Internet is not one normal instructions.
Found a very good example . The only pity is that the link to the original is broken.
Option - use URL:
// Π‘ΠΎΠ·Π΄Π°ΠΉΡΠ΅ ΠΎΠ±ΡΠ΅ΠΊΡ File Π² ΠΊΠΎΡΠ½Π΅ Π΄ΠΈΡΠ΅ΠΊΡΠΎΡΠΈΠΈ, ΠΊΠΎΡΠΎΡΠ°Ρ ΡΠΎΠ΄Π΅ΡΠΆΠΈΡ class-ΡΠ°ΠΉΠ». File file = new File("c:\\myclasses\\"); try { // ΠΡΠ΅ΠΎΠ±ΡΠ°Π·ΡΠΉΡΠ΅ File Π² URL URL url = file.toURI().toURL(); // file:/c:/myclasses/ URL[] urls = new URL[]{url}; // Π‘ΠΎΠ·Π΄Π°ΠΉΡΠ΅ Π½ΠΎΠ²ΡΠΉ class loader Ρ Π΄ΠΈΡΠ΅ΠΊΡΠΎΡΠΈΠ΅ΠΉ ClassLoader cl = new URLClassLoader(urls); // ΠΠ°Π³ΡΡΠ·ΠΈΡΠ΅ ΠΊΠ»Π°ΡΡ; MyClass.class Π΄ΠΎΠ»ΠΆΠ΅Π½ ΡΠ°ΡΠΏΠΎΠ»Π°Π³Π°ΡΡΡΡ Π² // Π΄ΠΈΡΠ΅ΠΊΡΠΎΡΠΈΠΈ file:/c:/myclasses/com/mycompany Class cls = cl.loadClass("com.mycompany.MyClass"); } catch (MalformedURLException e) { } catch (ClassNotFoundException e) { }
Source: https://ru.stackoverflow.com/questions/476416/
All Articles