windows Java 打印服务:PrintServiceLookup.lookupPrintServices 不返回联网打印机

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1035212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:41:54  来源:igfitidea点击:

Java Print Service: PrintServiceLookup.lookupPrintServices does not return networked printers

javawindowsprintingservice

提问by Khandelwal

If I run my JBoss application from the Windows command prompt I can get the list of printers (including networked printers just fine).

如果我从 Windows 命令提示符运行我的 JBoss 应用程序,我可以获得打印机列表(包括网络打印机就好了)。

If I run my JBoss application as a Windows service, I only get the list of printers that are directly connected to the machine. The networked printers don't show up.

如果我将 JBoss 应用程序作为 Windows 服务运行,我只能获得直接连接到机器的打印机列表。联网打印机不显示。

Here is the Java code I use to get the list of printers:

这是我用来获取打印机列表的 Java 代码:

PrintService[] printerServices = PrintServiceLookup.lookupPrintServices(null, null);

It doesn't appear to be a permissions problem, since according to our administrator, the permissions are setup just fine.

这似乎不是权限问题,因为根据我们的管理员的说法,权限设置得很好。

Does some have a better explanation, or is there a set of permissions that might be required to get the networked printers to show up?

有没有更好的解释,或者是否有一组权限可能需要让联网打印机出现?

回答by Khandelwal

You have to run the windows service as a user on the domain that has the appropriate permissions, not as LocalUser.

您必须以具有适当权限的域上的用户身份运行 Windows 服务,而不是以 LocalUser 身份运行。

You can also add networked printers using a tcp/ip connection, and the problem goes away.

您还可以使用 tcp/ip 连接添加联网打印机,问题就会消失。

回答by Thor Hovden

My colleague had this very same problem just minutes ago, but on a REDHAT LINUX system. His server had been rebooted and printer functionality worked only half way; lp worked, cups worked, but no access to printers from Java. He found out localhost had disappeared from the hosts file.

几分钟前,我的同事也遇到了同样的问题,但在 REDHAT LINUX 系统上。他的服务器已经重新启动,打印机功能只工作了一半;lp 工作,cups 工作,但无法从 Java 访问打印机。他发现 localhost 已经从主机文件中消失了。

His solution: add localhost to hosts file (but since you are on windows, this might not be your solution)

他的解决方案:将 localhost 添加到 hosts 文件(但由于您使用的是 Windows,这可能不是您的解决方案)

回答by Oleg Kokorin

it's appeared to be an issue with the network printers. any printer to be seen by JRE has to be in "shared" state. unfortunately network printers aren't.

这似乎是网络打印机的问题。JRE 看到的任何打印机都必须处于“共享”状态。不幸的是,网络打印机不是。

see: System Settings->Printers->PDF->->Shared (enable checkbox)

请参阅:系统设置->打印机->PDF->->共享(启用复选框)