简体   繁体   English

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

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

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. 如果我将JBoss应用程序作为Windows服务运行,我只能获得直接连接到机器的打印机列表。 The networked printers don't show up. 网络打印机不显示。

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? 有些人有更好的解释,或者是否有一组权限可能需要让网络打印机出现?

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连接添加联网打印机,问题就消失了。

My colleague had this very same problem just minutes ago, but on a REDHAT LINUX system. 几分钟前,我的同事遇到了同样的问题,但在REDHAT LINUX系统上。 His server had been rebooted and printer functionality worked only half way; 他的服务器已重新启动,打印机功能只有一半; lp worked, cups worked, but no access to printers from Java. lp工作,杯子工作,但无法从Java访问打印机。 He found out localhost had disappeared from the hosts file. 他发现localhost已经从hosts文件中消失了。

His solution: add localhost to hosts file (but since you are on windows, this might not be your solution) 他的解决方案:将localhost添加到hosts文件中(但由于你在Windows上,这可能不是你的解决方案)

it's appeared to be an issue with the network printers. 它似乎是网络打印机的一个问题。 any printer to be seen by JRE has to be in "shared" state. JRE看到的任何打印机都必须处于“共享”状态。 unfortunately network printers aren't. 不幸的是,网络打印机不是。

see: System Settings->Printers->PDF->->Shared (enable checkbox) 请参阅:系统设置 - >打印机 - > PDF - > - >共享(启用复选框)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM