Posted December 11, 20177 yr Allocate Console in Java??? When I try to run the bolded one it doesn't work: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();int compilationResult = compiler.run(null, null, null,sourceFile.getPath()); The run method can use streams to handle input and output:int run(InputStream in, OutputStream out, OutputStream err, String... arguments) When I run the program from console with java.exe or even javaw.exe all works ok. SO I think it fails because it doesn't have a console window or such... Anyone know how to solve the problem?
December 11, 20177 yr Author cmd = "java -jar "+'"'+cmd+'"'; Runtime rt = Runtime.getRuntime(); Process proc = rt.exec("cmd /c start "+cmd); When I execute this a console window is created, but still the compile method above doesn't work, the jar to exe converted exe with JarToExeProc works like a charm, and also the program in debug mode works ok (rt.exec is not needed).
December 11, 20177 yr Author Finded the problem: java.exe path must be fully specified: cmd = '"'+"C:\\Program Files (x86)\\Java\\jdk1.7.0_25\\bin\\java.exe"+'\"'+" -jar "+'"'+cmd+'"'; Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd);
December 11, 20177 yr Author private static void SetIsInValid() { IsInValid = true; try { if (System.in==null) IsInValid = false; System.in.available(); IsInValid = true; } catch(Exception exc) { IsInValid = false; } } I got the wrong idea, it has nothing to do with any Console window, The jar file must be executed by the JDK and not by JRE, this is why compilation fails, things starts to make some sense now!
Create an account or sign in to comment