Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Allocate Console in Java

Featured Replies

Posted

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?
 

  • 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).
 

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

 

  • 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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.