Bonjour a tous ,
Bon j'ai une classe Out1.java quand je fait : java -cp . Out1 ça marche et le résultat s'affiche par contre j'ai un autre programme java CompileAndRun
pour lancer le même programme Out1.java je reçois l'erreur " impossible de trouver ou charger la classe principale ,!!!!! ou es le problème?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
38
39
40
41 //---------------------------------Compile public static boolean compile(File filename, String classsource) throws IOException { // Create file FileWriter fstream = null; try { fstream = new FileWriter(filename); BufferedWriter out = new BufferedWriter(fstream); out.write(classsource); out.flush(); } finally { if (fstream != null) { try { fstream.close(); } catch (IOException e) { // silent } } } Process processCompile = Runtime.getRuntime().exec( new String[] { JAVA_BIN_PATH + "javac.exe",FOLDER + "Out1.java" } ); return printResult("Compile", processCompile)==0; } //------------------run public static void run(File file) throws IOException { System.out.println("Run java program: " + file); Process processRun = Runtime.getRuntime().exec(new String[] { JAVA_BIN_PATH + "javaw.exe", FOLDER + "Out1.java" },null, file.getParentFile()); printResult("Run", processRun); } private static String getClassName(File file) { String name = file.getName(); return name.substring(0,name.indexOf('.')); }
Partager