Esempio n. 1
0
        public static List <Class> java_From_ClassLoader_get_Loaded_Classes(this API_Jni4Net jni4Net, ClassLoader classLoader)
        {
            var classes = new List <Class>();
            var clClass = classLoader.getClass();

            while (clClass != java.lang.ClassLoader._class)
            {
                "{0} - {1}".info(clClass.str(), clClass.getSuperclass().str());
                clClass = clClass.getSuperclass();
            }

            var classes_Field = clClass.getDeclaredField("classes");
            var classes_Value = classes_Field.get(classLoader);

            var elements_Method = classes_Value.getClass().getMethod("elements", null);
            var elements        = elements_Method.invoke(classes_Value, null);


            while (elements.Invoke <bool>("hasMoreElements", "()Z"))
            {
                classes.add(elements.Invoke <java.lang.Class>("nextElement", "()Ljava/lang/Object;"));
            }

            return(classes);
        }
Esempio n. 2
0
 public static ClassLoader loadJar(this ClassLoader classLoader, string pathToJar)
 {
     try
     {
         var addUrl = classLoader.getClass()
                      .getSuperclass()
                      .getDeclaredMethod("addURL", new Class[] { URL._class });
         addUrl.setAccessible(true);
         addUrl.invoke(classLoader, new java.lang.Object[] { pathToJar.java_File().toURL() });
     }
     catch (Exception ex)
     {
         "[ClassLoader][loadJar] failed to load file {0} , exception: {1}".error(pathToJar, ex.Message);
     }
     return(classLoader);
 }
Esempio n. 3
0
        public static List <string> jarsInClassPath(this  ClassLoader classLoader)
        {
            var urls = classLoader.getClass().getMethod("getURLs", null).invoke(classLoader, null);

            return(urls.getElementsFromArray <URL>().toStringList().select((file) => file.remove("file:/")));
        }