Ajouter un argument à la VM en cours d'execution

Fermé
speedzealot Messages postés 18 Date d'inscription vendredi 24 juillet 2015 Statut Membre Dernière intervention 17 novembre 2015 - Modifié par speedzealot le 10/08/2015 à 15:56
speedzealot Messages postés 18 Date d'inscription vendredi 24 juillet 2015 Statut Membre Dernière intervention 17 novembre 2015 - 10 août 2015 à 17:31
Bonjour,

J'aimerai déplacer mes arguments de la JVM dans ma class main.

Donc au lieu de configurer Eclipse avec comme VMargs : -Djava.library.path=Slick2D, je voudrai mettre à la première ligne de mon main :
System.getProperties().put("java.library.path", "Slick2D");
// ou
System.setProperties("java.library.path", "Slick2D");

Sauf que j'ai le droit à une erreur "no lwjgl in java.library.path" ...

(Sachant que dans la librairie Slick2D j'ai bien sure lwjgl.jar, et que si je met
System.out.println(System.getProperties().getProperty("java.library.path"));

sur la ligne suivante, j'ai bien mon "Slick2D" ...)

j'aimerai quand même comprendre
(ce serai pour pouvoir lancer mon programme sans passer par un script/batch)
Merci
A voir également:

1 réponse

speedzealot Messages postés 18 Date d'inscription vendredi 24 juillet 2015 Statut Membre Dernière intervention 17 novembre 2015 3
Modifié par speedzealot le 10/08/2015 à 16:14
Ok c'est bon je l'ai :)

public static void addLibPath(String s){
	try {
		Field field = ClassLoader.class.getDeclaredField("usr_paths");
		field.setAccessible(true);
		String[] paths = (String[])field.get(null);
		for (int i = 0; i < paths.length; i++) if (s.equals(paths[i])) return;
		String[] tmp = new String[paths.length+1];
		System.arraycopy(paths, 0, tmp, 0, paths.length);
		tmp[paths.length] = s;
		field.set(null,tmp);
		System.setProperty("java.library.path", System.getProperty("java.library.path") + File.pathSeparator + s);
	} catch (IllegalAccessException e) {
		System.err.println("Failed to get permissions to set library path");
		e.printStackTrace();
	} catch (NoSuchFieldException e) {
		System.err.println("Failed to get field handle to set library path");
	        e.printStackTrace();
	}
}



il est aussi dit que cela ne marcherai pas sur toutes les plateformes/JVM.

marche avec windows7 64 bits, jre7 32bits

Pour plus de details : https://stackoverflow.com/questions/5419039/is-djava-library-path-equivalent-to-system-setpropertyjava-library-path
0
speedzealot Messages postés 18 Date d'inscription vendredi 24 juillet 2015 Statut Membre Dernière intervention 17 novembre 2015 3
Modifié par speedzealot le 10/08/2015 à 18:05
Sauf que ca ne résoud pas mon second objectif qui est de pouvoir lancer cette appli sans script : depuis eclipse ca marche très bien, mais depuis cmd j'ai le retour de mon erreur

ce qui m'amène à une question : peut-on creer une bibliothèque en cours d'execution (dans le main) ?
0