Disable java application from console / command window

Possible duplicate:
Is there a way to hide the win32 startup console from a Java program (if possible without JNI)

When I run the java swing application in a batch file on the windows, the console / command window remains open while the Java application is running. This creates an additional window on my taskbar that I would rather not have. But when I close the command window, it stops my Java application. Is there a way, possibly using the batch file or command line options or changing the code in my application, to exit java.exe after I run the swing application and the console window while my application is still running?

The main method is as follows:

public static void main(String args[]) {

    ApplContext applContext = new ApplContext();
    Throwable error = null;

    try {
        applContext.setUserConfigDir(args.length>0 ? args[0] : null);
        applContext.loadData();
        ApplTools.initLookAndFeel(Parameters.P_NIMBUS_LAF.of(applContext.getParameters()));
    } catch (Throwable e) {
        error = e;
    }

    // JWorkSheet is a JFrame.
    new JWorkSheet(applContext, error).setVisible();
}    
+3
2

javaw.exe, java. bat, start:

> start javaw.exe -jar myapp.jar

, , , . , , .

. java.exe - Windows. , , , . javaw.exe.

+6

, - , SwingUtilities.invokeLater(Runnable r). GUI , .

, :

public static void main(String[] args){
    SwingUtilities.invokeLater(new Runnable(){
        public void run(){
            JFrame yourWindow = new YourFrame();
            yourWindow.createAndShow();
        }
    }
}
+1

Source: https://habr.com/ru/post/1718960/


All Articles