Make an OSX app bundle for a Java program without user interface stay in Dock while the app is running

StackOverflow https://stackoverflow.com/questions/16309058

  •  13-04-2022
  •  | 
  •  

Question

I tried to create my first OSX app bundle for a Java application today. It works, but there is one problem and I could not find any solution for it.

The Java application is a web server without user interface. What happens when I start the app bundle, is the following:

  • The app icon bounces several times in the Dock and then disappears (I guess because no GUI is being displayed?).
  • However, the application is still running. Web server is available and I can see the running application in Activity Monitor and stop it from there.

The main purpose of this app bundle is to provide a demo application to people who are interested in trying the server out - easily without any setup, etc.

The application should remain in the Dock and users should be able to close (stop) the server in the Dock.

I imagine that this might be configurable in Info.plist somehow, but don't have any experience with it. Or probably there is something else I can do in order to achieve the desired behavior?

Thanks for any ideas or hints.

Was it helpful?

Solution

I found the answer to this problem today:

I didn't notice it when copying configuration details into Apple's Jar Bundler, but I had this in the VMOptions parameter (Info.plist file):

<key>Java</key>
<dict>
    [...]
    <key>VMOptions</key>
    <string>-Djava.awt.headless=true</string>
    [...]
</dict>

Passing -Djava.awt.headless=true to the Java VM was the problem. After removing this parameter, the application behaved just as I wanted. It doesn't have a window but a simple menu with quit option is there, so users can easily stop the application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top