CodeExplorer Posted December 11, 2017 Posted December 11, 2017 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?
CodeExplorer Posted December 11, 2017 Author Posted December 11, 2017 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).
CodeExplorer Posted December 11, 2017 Author Posted December 11, 2017 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);
CodeExplorer Posted December 11, 2017 Author Posted December 11, 2017 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!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now