views:

28

answers:

3

Hi, I have a simple server application, which I would like to run in the background. The following line works for me:

Runtime.getRuntime().exec("cmd /c start java -jar ..\\server\\server.jar -Dlog4j.configuration=file:src\\test\\resources\\log4j.properties -filename src\\test\\resources\\server.properties");

But it displays the cmd window and I am unable to destroy it. So I would like to use

Runtime.getRuntime().exec("java -jar ..\\server\\server.jar -Dlog4j.configuration=file:src\\test\\resources\\log4j.properties -filename src\\test\\resources\\scIntegration.properties");

But it simply doesn't connect to the server. So why is that?

A related question. How do I end the process? It is a server that "doesn't end". So I have to kill it and I would assume, that running the java only command would be capable to be destroyed, but with the cmd I have no luck there.

A: 

Try using an absolute path to the java programm.

For destroying: exec() returns a java.lang.Process, which you should be able to destroy. If not, you have to implement some type of callback to shut your server down, e.g. listening on a specific prot for a shutdown command.

ZeissS
I already tried absolute paths. No use. I can't implement anything in the server, that's the problem with Process.destroy().
Trimack
+2  A: 

You should split your command into an array in which first argument is the actual command to run and all the rest are command like arguments:

Runtime.getRuntime().exec(new String[] {"/usr/bin/java", "-jar", "..\\server\\server.jar" ...});
Piotr Maj
I have tried that with the same result :(
Trimack
A: 

The server is outputing something to stdout and in the shortened command version it didn't have a place to output, so it got stuck while trying to output some data. The solution is to pipe the stdout to eg some file.

Trimack