The Core Technologies Blog

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


Q & A: How can I see my Java Console Window when Running as a Service with AlwaysUp?

Q & A -Show Java Console Window
  I am running a Java application as a windows service with AlwaysUp. My JAR starts up fine and seems to be working as expected but I can’t see the Java console window to make sure that there are no errors. How can I see the console window?

— Alain Thiré, Thikro

Hi Alain. You cannot see your Java console window because it is running in a different Windows “Session”.

Let me explain a bit about Sessions and how they work:

  1. When you log into your PC, Windows creates a Session for you. That Session holds your desktop and all the programs you start. All your applications (processes) run inside that Session. Think of the Session as your own private room, holding all your things.

  2. If your wife logs in, she receives her own Session to hold all the applications she uses. Her Session is completely separate from yours and any program she starts will only be visible to her on her desktop. She gets her own private room.

  3. When your computer starts, windows creates a special Session for all services. That is, Windows Services have their own room. And because this is the first Session created, it is named Session 0.

Now when AlwaysUp starts your application as a Windows Service, it launches it in Session 0 (the home for all Windows Services). And because you are logged into a completely different Session (perhaps Session 1 or Session 2), you will not be able to see your application’s windows on your desktop. Your Java application isn’t in your room.

But fortunately that is not the end of the story. Here are three ways to see what Java is printing to the console.

Solution #1: Temporarily Switch to Session 0

Windows gives you the opportunity to view the Session 0 desktop whenever a window is displayed there. Click View the message when the Interactive Services Detection alert pops up:

Interactive Services Detection Dialog

AlwaysUp allows you to access Session 0 at any time. Simply select Tools > Switch to Session 0 from the menu:

Switch to Session 0 from the Menu

Or click the “monitor” button on the toolbar to do the same:

Switch to Session 0 from the Toolbar

Now be warned — Session 0 is a strange looking place! You won’t see a task bar, desktop icons or the familiar start button. Here is what the austere Session 0 looks like with Notepad running:

Session 0 with Notepad Running

Click Return now to revert to the safety of your normal desktop.

Note: Switching to Session 0 may not be a viable option on Windows 10 and Windows Server 2016 because you will be unable to use the keyboard and mouse in Session 0. Unfortunately there is no workaround and we cannot confirm if/when Microsoft will address this annoying problem.

Solution #2: Restart your Java application in your Session

A second way to view the Java window is to have AlwaysUp restart your Java application in your login session. Select Application > Restart in this session to have the console appear on your desktop, alongside your other windows:

Restart in this session

AlwaysUp will automatically return your application to Session 0 after you log off (or you can return it manually).

The obvious downside of this approach is that your application has to be stopped. Might a brief interruption cause problems? If so, restarting in your session may not be the solution for you.

Solution #3: Capture the Java console output to a file

The final solution reframes the problem. Instead of seeing the Java console window, is viewing the text printed in the window good enough?

If so, setup AlwaysUp to capture the console output to a text file. Activate the option and specify the full path to the log file on the Extras tab:

Capture Java console output

Simply open the text file to see what Java has printed to the console. Or even better, use a free “tail” utility to follow the file’s additions in real time. Both Powershell’s Get-Content cmdlet and Tail for Win32 have worked well for our team.

Best of luck with your Java application/service!

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

Leave a Reply

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