6

I made a java program with a GUI using eclipse so whenever I want to run it I run it there, but my friend wants to run it on his computer so I made a class-file using javac in command prompt and also made a batch-file to run the program. The problem is that every time ha runs it this command window is still in the background. So what I want is to make that box disappear, is it any way to do that?

Appreciate all answers :)

Tamil Selvan C
  • 19,913
  • 12
  • 49
  • 70

2 Answers2

14

Launch it with javaw instead of java. The Description for java mentions:

The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you don't want a command prompt window to appear. The javaw launcher will, however, display a dialog box with error information if a launch fails for some reason.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

Having another class to launch, I think is the best solution.

import java.io.IOException;
public class Main2 {

public static void main(String[] args) {

    try {
        String[] cmdArray = new String[ args.length + 1 ];
        cmdArray[0] = "javaw";
        for ( int a0=0; a0 < args.length; a0++ ) {
            cmdArray[ a0 +1 ] = args[a0];
        }
        Runtime.getRuntime().exec(  cmdArray ); 
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}

}

Then you need a bat, with something like

@echo off
set TMP_CLASSPATH=%CLASSPATH%
cd c:\WorkDir
set CLASSPATH=C:\WorkDir\mayapps.jar
set CLASSPATH=%CLASSPATH%;C:\WorkDir\lib\others.jar

java -cp "%CLASSPATH%"  Main2 -splash:mysplash.gif -Dlog4j.configuration=myapp.log4j  mymainclass  -param1=xxx -param2 etc