private static int runServer ( String extractDirectory , String serverName , String [ ] args ) throws IOException , InterruptedException { int rc = 0 ; Runtime rt = Runtime . getRuntime ( ) ; String action = "run" ; if ( System . getenv ( "WLP_JAR_DEBUG" ) != null ) action = "debug" ; // unless user specifies to enable 2PC, disable it if ( System . getenv ( "WLP_JAR_ENABLE_2PC" ) == null ) disable2PC ( extractDirectory , serverName ) ; String cmd = extractDirectory + File . separator + "wlp" + File . separator + "bin" + File . separator + "server " + action + " " + serverName ; if ( args . length > 0 ) { StringBuilder appArgs = new StringBuilder ( " --" ) ; for ( String arg : args ) { appArgs . append ( " " ) . append ( arg ) ; } cmd += appArgs . toString ( ) ; } System . out . println ( cmd ) ; if ( platformType == SelfExtractUtils . PlatformType_UNIX ) { // cmd ready as-is for Unix } else if ( platformType == SelfExtractUtils . PlatformType_WINDOWS ) { cmd = "cmd /k " + cmd ; } else if ( platformType == SelfExtractUtils . PlatformType_CYGWIN ) { cmd = "bash -c " + ' ' + cmd . replace ( ' ' , ' ' ) + ' ' ; } Process proc = rt . exec ( cmd , SelfExtractUtils . runEnv ( extractDirectory ) , null ) ; // run server // setup and start reader threads for error and output streams StreamReader errorReader = new StreamReader ( proc . getErrorStream ( ) , "ERROR" ) ; errorReader . start ( ) ; StreamReader outputReader = new StreamReader ( proc . getInputStream ( ) , "OUTPUT" ) ; outputReader . start ( ) ; // now setup the shutdown hook Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( new ShutdownHook ( platformType , extractDirectory , serverName , outputReader , errorReader ) ) ) ; // wait on server start process to complete, capture and pass on return code rc = proc . waitFor ( ) ; return rc ; }
Run server extracted from jar If environment variable WLP_JAR_DEBUG is set use server debug instead