Guest User

Untitled

a guest
Jul 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. File f = new File(nomJar);
  2. u = f.toURI().toURL();
  3. URLClassLoader loader = new URLClassLoader(new URL[]{u});
  4.                         JarFile jar = new JarFile(f.getAbsolutePath());
  5.                        
  6.                         Class jeu = Class.forName(nomClasse, true, loader);
  7.                        
  8.                         status.setText("Classe " + jeu.getName() + " chargée");
  9.                        
  10.                         Constructor constructors[] = jeu.getDeclaredConstructors();
  11.                         Constructor constructor = null;
  12.                         for(int i=0;i<constructors.length;i++){
  13.                             if(constructors[i].getParameterTypes().length == 0){
  14.                                 constructor = constructors[i];
  15.                             }
  16.                         }
  17.                         if(constructor == null)
  18.                             status.setText("Impossible de trouver un constructeur valide");
  19.                        
  20.                         Method getNom = jeu.getDeclaredMethod("getNom",null);
  21.                         final Object instanceJeu = constructor.newInstance();
Add Comment
Please, Sign In to add comment