The Core Technologies Blog

Our Software // Windows Services // 24×7 Operation


Q & A: How do I get AlwaysUp to run Java.exe in the PATH?

Q & A - Java

I run a Java program EchoLink Proxy as part of Ham Radio networking. A routine update replaced the Java folder with its new version number thus my AlwaysUp Application field to run the program needed manual edit from:

C:\Program Files (x86)\Java\jre1.8.0_171\bin\java.exe

to

C:\Program Files (x86)\Java\jre1.8.0_181\bin\java.exe

I tried simply providing “Java.exe” (which works from a CMD prompt) but AlwaysUp requires the full-path. How can I get AlwaysUp to run the Java.exe in my PATH environment variable?

— Anonymous


Hi. AlwaysUp expects a full path, so I see the problem!

We recommend adding a “layer of indirection” to solve the problem. Please:

  1. Create a new Windows batch file that runs your full java command line. However, instead of specifying the full path to java, simply use java.exe.

    When run, the batch file will use whatever java.exe is in your Windows account’s PATH variable.

    Here is what our simple batch file (saved to “C:\Tools\start-java-app.bat”) looks like:

    Start Java Batch File

    Please open a command prompt, run your batch file and confirm that it launches your program (EchoLink Proxy) as you expect.

  2. Update your AlwaysUp entry to run the new batch file. Specify the full path to the batch file in the Application field on the General tab:

    Run the Batch File in AlwaysUp

    Be sure to clear the Arguments field if it contains the parameters for the Java command line! Those should already appear in the batch file.

  3. And on the AlwaysUp Logon tab, specify the Windows account you are logged in to right now. Java must be launched in this account so that it finds the correct PATH environment value.

    Set the account for running Java as a service
  4. Finally, update the new batch file to add a 5 second delay at the end. We recommend using the Windows TIMEOUT command, but there are several alternatives:

    timeout /t 5

    Without this adjustment, the batch file may exit very quickly and fool AlwaysUp into thinking that the batch file failed to start properly.

    Add a Timeout to the Batch File
  5. Save your batch file — and your settings in AlwaysUp.

Now, when you start your modified entry from AlwaysUp, the following will happen:

  1. AlwaysUp will start the batch file

  2. The batch file will launch Java from the PATH, as you have configured

  3. The batch file will “sleep” for 5 seconds

  4. The batch file will exit

  5. AlwaysUp will notice that the batch file has exited and “attach” to the Java.exe child process

  6. AlwaysUp will continue to monitor Java.exe and restart it (via the batch file) if it ever crashes/fails/exits.

Any monitoring, reporting and alerts you have configured should continue to work as they did before.

Please let us know if you run into any trouble implementing this approach!

Posted in AlwaysUp | Tagged , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>