Class loader java required



  • It's necessary to make a class loader from the java file.

    I've heard what this is done by redefining ClassLoader operators, how can it be done?

    There's not one normal online instruction.



  • https://stackoverflow.com/a/6219855/980828 ♪ It's just a pity that the reference to the original battle.

    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) {
    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2