'PrintServiceLookup.lookupDefaultPrintService() returns null when run as a windows service

The jar file is working fine and giving name of the default printer.

PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
System.out.println("Default Printer  "+ defaultPrintService );

When same jar is run as a service , this snippet prints null. The print is also working with the service. It just cannot fetch default printers. Any idea how to make it work?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source