用java从AS400服务器获取打印机
我无法获取 AS400 上的打印机。
我尝试过:
PrintService[] services = PrinterJob.lookupPrintServices();
没有找到任何服务。
我还搜索了 JTOpen API。我什么也没找到。
有人可以帮助我吗?
I can't get the printers on the AS400.
I tried :
PrintService[] services = PrinterJob.lookupPrintServices();
No services has been found.
I also searched on JTOpen API. I didn't find anything.
Somebody can help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PrinterJob.lookupPrintService()
默认为DocFlavor.SERVICE_FORMATTED.PAGEABLE
风格。可能是您没有支持该风格的打印机。尝试运行此命令来检查是否找到任何打印机
并检查它们支持哪些类型。
另外,你用的是iSeries吗?操作系统400?哪个Java?
PrinterJob.lookupPrintService()
defaults toDocFlavor.SERVICE_FORMATTED.PAGEABLE
flavor. Could be you have no printers supporting that flavor.Try running this to check if there are ANY printers found
And check what kinds of flavors they support.
Also, are you on iSeries? OS 400? And which Java?
我面临同样的问题,终于找到了解决方案:根据 Java 打印服务 IBM 文档 您必须将 2 个 jar 添加到 Java 的类路径中,以检测 AS400 上的打印机(和打印)。
这些 jar 文件应位于
在我的例子中,AS400 上的
jt400Native.jar
对于我们的应用程序来说太旧了(Java 1.1 与 Java 1.8),导致应用程序启动时崩溃。我从 https://mvnrepository.com/artifact/net.sf 获取了最新的一份。 jt400/jt400 并且成功了。如果您从 jar 运行应用程序,则无法使用
-cp
和-classpath
,这些选项将被忽略,因为类路径是通过 Manifest 文件设置的。就我而言(SpringBoot Java 8 Gradle 项目),我曾经
将这些 jar 添加到 Manifest 文件中的类路径中。
I was facing the same issue and finally found a solution : according to Java Print Service IBM Documentation you have to add 2 jars to the classpath for Java to detect printers (and print) on AS400.
These jar files should be located at
In my case the
jt400Native.jar
on the AS400 was way too old for our application (Java 1.1 vs Java 1.8) and caused crash on app startup. I took the latest one from https://mvnrepository.com/artifact/net.sf.jt400/jt400 and it worked.If you run your app from a jar you cannot use
-cp
and-classpath
, these options are ignored because classpath is set via Manifest file.In my case (SpringBoot Java 8 Gradle project), I used
to add theses jar to the classpath in Manifest file.