添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
风度翩翩的芹菜  ·  SQL server Merge into ...·  1 年前    · 
冷静的饼干  ·  Linq中的group ...·  1 年前    · 
幸福的冲锋衣  ·  SQL ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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

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.

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

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.

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

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.

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

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.

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.