lancer une application - java.lang.reflect.InvocationTargetException
Bonjour,
Le problème concerne cette applet qui doit ouvrir dolphin sous linux, et explorer.exe sous windows :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import java.io.IOException;
import java.applet.*;
import java.awt.*;
public class LanceAppli extends Applet{
public void paint(Graphics g)
{
g.drawString("Hello !!!", 30, 30);
}
public int execProg() {
String nomSex = System.getProperty("os.name").toLowerCase();
System.out.println(nomSex);
String dir = "/home/damien/www";
String chU = "dolphin " + dir;
String chW = "C:\\Windows\\explorer.exe " + dir;
// String chW="C:\\Windows\\command.com /C set";
String cmd = "";
// Que va-t-on exécuter ?
if (nomSex.indexOf("windows") > -1)
cmd = chW;
else if (nomSex.indexOf("linux") > -1)
cmd = chU;
else
System.exit(1);
// Objet environnement d'exécution
Runtime r = Runtime.getRuntime();
try {
Process p = r.exec(cmd);
} catch (IOException e) {
//System.out.println("" + e);
return 0;
}
return 1;
}
} // fin LanceAppli.java |
Cette applet s'exécute correctement en tant qu'appli java en remplaçant execProg par une main.
L'applet est signée et s'exécute ainsi :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| <html>
<head>
<script type="text/javascript">
function TestApplet(){
test = document.getElementById('apExec').execProg();
}
</script>
</head>
<body>
<input type="button" id="lanceApplet" value="Explorateur" onclick="TestApplet()">
<applet codebase="./class/" code="LanceAppli.class" archive="LanceAppli.jar"
width="500" height="200" id="apExec">
</applet>
</body>
</html> |
Mais quand je clique sur le bouton dans firefox , j'ai l'erreur suivante :
Citation:
uncaught exception: java.security.PrivilegedActionException: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
Je ne vois pas ou est le problème, je ne sait pas comment rendre plus parlant l'erreur (je n'ai que des notions en java...).
Merci d'avance pour toute aide