Hi all,
I'm working on a Java application that essentially stays running throughout a while loop. I have added code that, when an invalid value is received, the program breaks out of the while loop. I want to get my Java application to launch another instance of itself when this happens, and then kill itself.
Using Runtime.getRuntime().exec(), I executed the command "java -jar myJar.jar" and, as hoped, the application does restart. So far so good.
However, when running the application the first time in the command prompt, I am able to see all of my logger output, but when I restart, the command prompt goes away and the application runs without the command prompt available for logger output. I've tried updating the command to say "cmd /k pushd %APP_HOME% && java -jar %APP_HOME% + "\\myJar.jar" where APP_HOME is an environment variable that maps to the path of my JAR and although I've been able to run this command from the Run menu of Windows XP without a problem (meaning the application runs), but when the command is executed upon a restart attempt, nothing seems to change.
Due to the nature of the business I work at, I cannot display the full source code. However, here is the code that attempts the restart. Note that startCommand at this point equals "java -jar myJar.jar" or "cmd /k pushd %APP_HOME% && java -jar %APP_HOME% + "\\myJar.jar" (I've tried both):
try
{
restartProcess =
Runtime.getRuntime().exec(startCommand);
}
catch (IOException e2)
{
logger.warn("Exception triggered.");
e2.printStackTrace();
}
System.exit(0);
Does anyone know why the console window doesn't get re-opened in this case?
Thanks in advance for the assistance.
I'm working on a Java application that essentially stays running throughout a while loop. I have added code that, when an invalid value is received, the program breaks out of the while loop. I want to get my Java application to launch another instance of itself when this happens, and then kill itself.
Using Runtime.getRuntime().exec(), I executed the command "java -jar myJar.jar" and, as hoped, the application does restart. So far so good.
However, when running the application the first time in the command prompt, I am able to see all of my logger output, but when I restart, the command prompt goes away and the application runs without the command prompt available for logger output. I've tried updating the command to say "cmd /k pushd %APP_HOME% && java -jar %APP_HOME% + "\\myJar.jar" where APP_HOME is an environment variable that maps to the path of my JAR and although I've been able to run this command from the Run menu of Windows XP without a problem (meaning the application runs), but when the command is executed upon a restart attempt, nothing seems to change.
Due to the nature of the business I work at, I cannot display the full source code. However, here is the code that attempts the restart. Note that startCommand at this point equals "java -jar myJar.jar" or "cmd /k pushd %APP_HOME% && java -jar %APP_HOME% + "\\myJar.jar" (I've tried both):
try
{
restartProcess =
Runtime.getRuntime().exec(startCommand);
}
catch (IOException e2)
{
logger.warn("Exception triggered.");
e2.printStackTrace();
}
System.exit(0);
Does anyone know why the console window doesn't get re-opened in this case?
Thanks in advance for the assistance.