charger dynamiquement un jar
Bonjour
j'ai vu sur ce forum que l'on pouvait charger dynamiquement un jar, j'ai donc utilisé le code suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
File ComponentLibrary = new File("Eeprom.jar");
try {
URL[] urlList = {ComponentLibrary.toURL()};
ClassLoader loader = new URLClassLoader(urlList);
String className = "ComponentDefinition";
try {
Object MyObject = Class.forName(className, true, loader).newInstance();
} catch (ClassNotFoundException ex1) {
System.out.println("Exception found for " + ex1.toString());
} catch (IllegalAccessException ex1) {
System.out.println("Exception found for " + ex1.toString());
} catch (InstantiationException ex1) {
System.out.println("Exception found for " + ex1.toString());
}
} catch (MalformedURLException ex) {
} |
mais je déclenche l'exception suivante:
Exception found for java.lang.InstantiationException: ComponentDefinition
Donc je trouve bien ma classe mais je n'arrive pas l'instancier
La classe dans le jar est définie comme suis
Code:
1 2 3 4 5 6 7
|
public class ComponentDefinition {
public ComponentDefinition() {
System.out.println("Ce marche");
}
} |
Ou est donc mon problème
merci d'avance pour votre aide