Jump to content
Tuts 4 You
CodeExplorer

Allocate Console in Java

Rate this topic

Recommended Posts

CodeExplorer

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?
 

Share this post


Link to post
Share on other sites
CodeExplorer
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).
 

Share this post


Link to post
Share on other sites
CodeExplorer

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);

 

Share this post


Link to post
Share on other sites
CodeExplorer
    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!

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...